Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My lab problem says : \"Q7. Write a prototype and function definition for a void

ID: 3632833 • Letter: M

Question

My lab problem says :
"Q7. Write a prototype and function definition for a void function called GetRating() of anemployee with one reference parameter of type char . The function repeatedly prompts the user to enter a character at the keyboard until one of these has been entered: E, G, A, P to represent Excellent, Good, Average, Poor."

I get an error when I type in the letters E,G,A & P. If I type G, it executes "invalid try again", then I type A and it executes "the rating is A". Then I run the program again and I type A first and I get "invalid try again", next I type G this time and it works and outputs "the rating is G"

Please help me understand the error. I can't figure it out. My program so far is this :



#include <cstdlib>
#include <iostream>

void GetRating(char& letter);

using namespace std;
int main()
{
char letter;

cout << "Enter employee rating." << endl;
cout << "Use E, G, A, or P : ";
cin >> letter;

while((letter != 'E') && (letter != 'G')
&&(letter != 'A') && (letter != 'P'));
{
cout << "Rating invalid. Enter again: ";
cin >> letter;
}
cout << "That was rating = " << letter << endl;
system("PAUSE");

Explanation / Answer

void GetRating (char& letter)
{
cout << “Enter employee rating.” << endl;
cout << “Use E, G, A, or P : ” ;
cin >> letter;
while ( (letter != ‘E’) && (letter != ‘G’) &&
(letter != ‘A’) && (letter != ‘P’)
)
{
cout << “Rating invalid. Enter again: ”;
cin >> letter;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote