I have to format my program in a certain structure. The structure is
//Program Header
int main()
//Declarations
//Inputs
//Calculations/Processings
//Outputs
//Exit
Here's my code:
I just need help figuring out what goes where.
Thanks in advance
When posting code, please put it code tags. Look for the "Format:" section to the right of the edit box. Highlight your code and click the <> button. Here is your code indented and tagged. See my comments below:
Note that when checking for a B you don't have to check if avg<90 because you're guaranteed that it is. If it were greater than 90, then the code that checks for an "A" would have caught it.
Other than this, the code looks good but you need to rearrange it to match the structure that the assignment calls for. That structure is good because it separates input, calculation and output. It's always a good idea to separate these three because it's quite common to have to change one without having to change the others. For example, a phone app might have a different interface than a PC program.
Try rearranging your code into these functions:
1 2 3 4 5 6 7 8 9 10 11 12
// Get the user name and, if the name isn't "done", the scores. Return false if
// the name is "done", true otherwise:
bool getInput(string &name, int scores[10]);
// Compute the average from a set of grades
float computeAverage(int scores[], numScores);
// Compute the letter grade for an average
string computeGrade(float average);
// output the students name, numeric average and letter grade
void output(const string &name, float average, const string &grade);
Now the main program looks like this:
1 2 3 4 5 6 7 8 9 10 11 12
int main(int argc, char *argv[])
{
string name;
int scores[10];
while (getInput(name, scores)) {
float avg = computeAverage(scores,10);
string grade = computeGrade(average);
output(name, avg, grade);
}
return(EXIT_SUCCESS);
}
The case statements that you have don't compile for me. If they work for you then your compiler supports a non-standard syntax. That's why I'm saying that you should change switch statement to an if/then/else