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

I need some help with my code. I keep getting errors that say uninitialized loca

ID: 3924581 • Letter: I

Question

I need some help with my code. I keep getting errors that say

uninitialized local variable 'A' used

uninitialized local variable 'B' used

uninitialized local variable 'C' used

uninitialized local variable 'D' used

uninitialized local variable 'F' used

here is the code, in c++

#include <iostream>
#include <string>

using namespace std;

int main()
{
   char grade;
   char A, B, C, D, F;

   cout << "What Letter grade did you earn in Programming I ? ";
   cin >> grade;
  
      

   if (grade == A)
   {
       cout << " an A - excellent work! ";
   }

   else if (grade == B)
   {
       cout << "you got a B good job ";
   }

   else if (grade == C)
   {
       cout << "earning a C is satisfactory ";
   }

   else if (grade == D)
   {
       cout << "while D is passing, there is a problem ";
   }

   else if (grade == F)
   {
       cout << "you failed - try harder next time ";
   }
   else
       {
           cout << " You did not enter an A,B,C,D, or F ";
       }

return 0 ;

}

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
int main()
{
char grade;
//char A, B, C, D, F;
cout << "What Letter grade did you earn in Programming I? ";
cin >> grade;
  
  
if (grade == 'A')
{
cout << "an A - excellent work! ";
}
else if (grade == 'B')
{
cout << "You got a B good job ";
}
else if (grade == 'C')
{
cout << "earning a C is satisfactory ";
}
else if (grade == 'D')
{
cout << "while D is passing, there is a problem ";
}
else if (grade == 'F')
{
cout << "You failed - try harder next time ";
}
else
{
cout << "You did not enter an A,B,C,D, or F ";
}
return 0 ;
}