Hello again, all! This is supposed to be a somewhat simple program using arrays and a function that returns a value.
This is a constant I declared above the main:
const int SIZE = 3;
Then, I wrote this prototype above the main:
float getTotal(string,int);
Inside the int main, I wrote:
1 2 3 4
|
string exams[] = { "Exam 1", "Exam 2", "Exam 3" };
int scores[SIZE];
float total;
total = getTotal(exams,scores);
|
Finally, I wrote this definition below the main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
float getTotal(string exams, int scores)
{
for (int i = 0; i < SIZE; i++)
{
cout << "\n\t\t\t\tEnter " << exams[i] << ": ";
cin >> scores[i];
//loop until a valid score is entered...
while (scores[i] < 0 || scores[i] > 100)
{
system("CLS");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout << "\t\t\t\t "
<< scores[i] << " is invalid!";
cout << "\n\t\t Please enter a value in the range 1-100: ";
cin >> scores[i];
cout << "\n\n\n\n\n\t\t";
}
}
float total = (scores[0] + scores[1] + scores[2]);
return total;
}
|
Basically, this is supposed to display "Enter Exam 1" then "Enter Exam 2" then "Enter Exam 3". Using cin, the user enters the exam scores into an integer array named scores. Then the 3 scores are added into a float called total, which is then supposed to be returned.
The error I am getting is:
conversion from `std::string*` to non-scalar type `std::string` requested
I don't know how to fix this... Can anyone help?