View more random threads:
- Programme Not Run in C++ giving erros 2011
- how i can leave spaces between my program output
- the source file is not compile in c++
- how does cin actually work in 2011
- info regarding "source file not compiled"
- HUFFMAN ENCODING in C++ 2012
- How many types of Array are there in C++?
- c++ code 2011
- ASCII code of c++
- Overloaded >> operator not reading more than first line...
Code:#include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; const int MAX_SCORES = 50; ifstream infile; void report(int numItems, string name[], int wins[], int losses[]); int readData(string name[], int wins[], int losses[]); void findAverage(int wins[], int losses[]); int main() { string name[MAX_SCORES]; int wins[MAX_SCORES]; int losses[MAX_SCORES]; int numItems; double average; numItems = readData(name, wins, losses); average = findAverage(wins, losses); report(numItems,name,wins,losses); findAverage(wins,losses); } int readData(string name[], int wins[], int losses[]) { infile.open("players.txt"); int count=0; while(infile.peek() !=EOF) { infile >> name[count] >> wins[count] >> losses[count]; count++; infile.ignore(1); } infile.close(); return count; } void report(int numItems, string name[], int wins[], int losses[]) { for (int i=0; i<numItems; i++) cout << name[i] << " " << wins[i] << " " << losses[i] << endl; } void findAverage(int numItems, int wins[], int losses[]) { double average; for(int i= 0; i <= numItems; i++) average= (wins[numItems]*100)/losses[numItems]; cout<< "The average value is: "<<average<<endl; } /*void bubbleSort (int numItems, string name[], int wins[], int losses[]) { string temp; int iteration; int index; for (iteration=1;iteration<numItems;iteration++) { for (index=0; index=numItems-iteration;index++) if (name[index]>name[index+1]); } temp=name[index]; name[index]=name[index+1]; name[index+1]=temp; cout << temp << endl; }*/
Sponsored Links
There are currently 1 users browsing this thread. (0 members and 1 guests)