David Weeks
asked on
How to write a C++ program for student and grades?
I am trying to write a C++ program to only input 10 student last names, number of correct answers, and total number of questions. The program will use a loop for 10 students only. The program will print out like this.
Greater than 90 should say Excellent, 80-90 should say Well Done, 70-80 should say Good, 60-70 Needs Improvement, and under 50 Failed.
smith 83% .83333 Well Done
This is a format of the printout. Should be 10 lines of different name and so on.
Greater than 90 should say Excellent, 80-90 should say Well Done, 70-80 should say Good, 60-70 Needs Improvement, and under 50 Failed.
smith 83% .83333 Well Done
This is a format of the printout. Should be 10 lines of different name and so on.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you have any further issues?
to add to jkr's solution:
there are more issues in your code:
1. the student name was asked for but you have no code to get the input from user cause you
mixed up studentname and studentscore.
2. you better use a for loop instead of a while loop like 'for (int count = 0; count < 10; ++count)'.
that makes sure that the count properly was incremented after each loop cycle.
usually in c and c++ you were using a zero-based loop counter what avoids mistakes
when using it as index for arrays which are zero-based as well.
3. you may use 'else if' instead of 'if' statements when checking the percentage for ranges less than 90.
that spares the check for the upper boundary (if (perc > 90) ... else if (perc > 80) ... else if (perc > 70) ...)
4. use a statement like 'getline(cin, strinput);' at end of main before return. then the program
stops at end waiting for input and you can check the output in the console window (shell)
if you run the program from the ide. alternatively, if running the program with debugger,
you may set a breakpoint to the return statement.
note, for input you should use function call of getline(cin, strinput) instead of 'cin >> ...' . that allows to properly handle the case when a user wants to quit (for example by a statement like 'if (strinput == "quit") break;' ) .it also allows spaces for text input. the disadvantage is that you need to check and convert the string input, if a number was required. you may use a temporary stringstream for that purpose or - maybe easier - use a function like strtol or atoi.
Sara
there are more issues in your code:
1. the student name was asked for but you have no code to get the input from user cause you
mixed up studentname and studentscore.
2. you better use a for loop instead of a while loop like 'for (int count = 0; count < 10; ++count)'.
that makes sure that the count properly was incremented after each loop cycle.
usually in c and c++ you were using a zero-based loop counter what avoids mistakes
when using it as index for arrays which are zero-based as well.
3. you may use 'else if' instead of 'if' statements when checking the percentage for ranges less than 90.
that spares the check for the upper boundary (if (perc > 90) ... else if (perc > 80) ... else if (perc > 70) ...)
4. use a statement like 'getline(cin, strinput);' at end of main before return. then the program
stops at end waiting for input and you can check the output in the console window (shell)
if you run the program from the ide. alternatively, if running the program with debugger,
you may set a breakpoint to the return statement.
note, for input you should use function call of getline(cin, strinput) instead of 'cin >> ...' . that allows to properly handle the case when a user wants to quit (for example by a statement like 'if (strinput == "quit") break;' ) .it also allows spaces for text input. the disadvantage is that you need to check and convert the string input, if a number was required. you may use a temporary stringstream for that purpose or - maybe easier - use a function like strtol or atoi.
Sara
ASKER
Open in new window