#include<iostream> #include<string> #include<fstream> #include<iomanip> using namespace std; int const SIZE = 10; int getValidInput(string driverName[], double judgesScores[][SIZE], double degreeDifficulty[]) { int length = 0; cout<<"Enter Driver Name, or ctrl z to exit: "; getline(cin, driverName[length]); while(!cin.eof()) { for(int ctr = 0; ctr <= 4; ctr++) { cout<<"Enter the score given by the jodges: "; cin>>judgesScores[length][ctr]; while(judgesScores[length][ctr] <= 0 || judgesScores[length][ctr] > 10.0 || cin.fail()) { cin.clear(); cout<<"Scores mus be between 1.0 and 10.0: "; cin>>judgesScores[length][ctr]; } } cout<<"What was the degree of difficulty: "; cin>>degreeDifficulty[length]; while(degreeDifficulty[length] <= 0 || degreeDifficulty[length] > 1.67 || cin.fail()) { cin.clear(); cout<<"Degree of difficulty must be between 1.0 and 1.67: "; cin>>degreeDifficulty[length]; } length ++; cin.ignore(80, '\n'); cin.clear(); cout<<"Enter Driver name, or ctrl z to exit: "; getline(cin, driverName[length]); } return length; } void addScores(double driverScore[], double judgesScores[][SIZE], int length) { double totalScore = 0; for(int ctr = 0; ctr <= 4; ctr++) { totalScore += judgesScores[length][ctr]; } driverScore[length] = totalScore; cout<<driverScore[length]; } int main() { cout<<fixed; string driverName[SIZE]; double driverScore[SIZE]; double judgesScores[5][SIZE]; double degreeDifficulty[SIZE]; int length = 0; length = getValidInput(driverName, judgesScores, degreeDifficulty); //while(length != 0) //{ addScores(driverScore, judgesScores, length); //} system("Pause"); }
This post has been edited by ButchDean: 31 May 2011 - 02:43 PM
Reason for edit:: Please use code tags!