Totaling scores in C++ -


okay when run code total equal 0 , messes average , grade.i not sure doing wrong total += scores function should be, yet still not adding scores.

int validatenumber(int, int, int); 

in main() function

int num, score, total = 0; 

and

validatenumber(num, score, total); 

and definition

int validatenumber(int num, int score, int total) {   while (num < 1 || num > 4) {     cout << over3 << num << " not between 1 , 4! try again: ";     cin >> num;   }   system("cls");   (int = 1; <= num; i++) {     cout << over3 << "enter score " << << ": " << endl;     cout << over3 << "enter value 0 100: ";     cin >> score;     while (score < 0 || score > 100) {       cout << over3 << score            << " not between 0 , 100! renter score: " << << ": ";       cin >> score;     }     total += score;   }   return total; } 

if want implement validate() function did here,

validatenumber(num,score,total); 

you can make void , pass variable total reference. e.g,

void validatenumber(int num, int score, int &total) {   while (num < 1 || num > 4) {     cout << over3 << num << " not between 1 , 4! try again: ";     cin >> num;   }   system("cls");   (int = 1; <= num; i++) {     cout << over3 << "enter score " << << ": " << endl;     cout << over3 << "enter value 0 100: ";     cin >> score;     while (score < 0 || score > 100) {       cout << over3 << score            << " not between 0 , 100! renter score: " << << ": ";       cin >> score;     }     total += score;   } } 

and rest same... otherwise wouldn't have use 3 arguments in case. e.g,

int validatenumber(int num) {   int total=0,score;   while (num < 1 || num > 4) {     cout << over3 << num << " not between 1 , 4! try again: ";     cin >> num;   }   system("cls");   (int = 1; <= num; i++) {     cout << over3 << "enter score " << << ": " << endl;     cout << over3 << "enter value 0 100: ";     cin >> score;     while (score < 0 || score > 100) {       cout << over3 << score            << " not between 0 , 100! renter score: " << << ": ";       cin >> score;     }     total += score;   }   return total; } 

and call:

int num, total; ... total=validatenumber(num); 

hope helped...


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -