Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //to use cout and cin and endl// allows using cout without std::cout
- #include <string> // to use string data type
- #include <fstream>
- #include <iomanip>
- //Daniel Clutts
- using namespace std;
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void printArray(int average[], int n)
- {
- for (int i=0; i < n-1; i++){
- cout << average[i] << ", ";
- }
- cout << average[n-1] <<endl;
- }
- void highToLow(int average[], int n, int median){
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n-i-1; j++){
- if (average[j] < average[j+1]){
- swap(&average[j], &average[j+1]);
- }
- }
- }
- printArray(average, n);
- //median=[5];
- cout <<" The median is " << median << endl;
- }
- int main()
- {
- ifstream myfile;
- ofstream myfile2; //test output
- myfile.open("C:/Users/wgund/Desktop/Bowlers2.txt");
- myfile2.open("c:/users/wgund/desktop/testttt.txt");
- string names[10]; //string
- float scores[10][3];
- float highest =0;
- float lowest =9999;
- int highestplayer =0;
- int lowestplayer =0;
- int player =0;
- int score=0;
- float average[10]={0,0,0,0,0,0,0,0,0,0};
- string line;
- cout << "Player name" << "\t\tscore 1 " << "\t\tscore 2 " << "\t\tscore 3" << "\t\t\taverage" << endl;
- for(int i=0; i<40; i++){ //
- int v=i%4;
- getline(myfile,line);
- if(v==0){
- names[player]=line;
- player++;
- }
- else{
- scores[player-1][v-1] = std::stoi(line);
- }
- }
- for (int i=0; i<10; i++){
- cout << names[i];
- myfile2 << names[i] << " ";
- for(int j=0; j<3; j++){
- myfile2 << scores[i][j] << " ";
- cout << '\t' << '\t' << '\t' << scores[i][j];
- average[i]=(average[i]+scores[i][j]); // Averages each players 3 scores
- }
- average[i]=average[i]/3.0; // averages each player 3 scores
- if(average[i] > highest){ // next two if statements determine highest and lowest
- highest=average[i];
- highestplayer=i;
- }
- if (average[i] < lowest){
- lowest=average[i];
- lowestplayer=i;
- }
- cout << '\t' << '\t' << '\t' << average[i] << endl;
- }
- float averages[] = {0,0,0};
- //Averages
- for(int i = 0; i < 10; i++){
- for(int j = 0; j < 3; j++){
- averages[j] = (averages[j] + scores[i][j])/2;
- }
- }
- //cout << "Game averages" << setw(18) << averages[0] << " " <<averages[1] << " " << averages[2] << endl;
- //cout << setw(8) << "Player " << names[lowestplayer] << " \t\thad the lowest score." << endl;
- //cout << "Their scores were " << scores[lowestplayer][0] << '\t' << scores[lowestplayer][1] << '\t' << scores[lowestplayer][2] << endl;
- //cout << "Their average was " << average[lowestplayer] << endl;
- //cout << setw(8) << "Player " << names[highestplayer] << " \t\thad the highest score." << endl;
- //cout << "Their scores were " << scores[highestplayer][0] << " " << scores[highestplayer][1] << " " << scores[highestplayer][2] << endl;
- //cout << "Their average was " << average[highestplayer] << endl;
- cout << highToLow;
- myfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement