Home > Back-end >  For help! For help!
For help! For help!

Time:09-19

I wrote a simple program, so don't Run, The report (The Run - Time Check Failure # 3 - The variable 'g' is being 2 without being an initialized) error, using VS2019, bosses help me
#include
#include
Int main ()
{
Float x;
Char g;
Scanf_s (" % f ", & amp; X);
Int y=x/10;
The switch (y)
{
Case '0' :
Case '1' :
Case '2' :
Case '3' :
Case '4' :
Case '5' : g='E'; break;
Case '6' : g='D'; break;
Case '7' : g='C'. break;
Case '8' : g='B'; break;
Case '9' :
Case '10' : g='A';
}
Printf (" % % d c, g, y);
return 0;
}

CodePudding user response:

Case '10' have grammar mistakes, single quotation marks on the inside is one character at a time, "10" is two characters,

CodePudding user response:

 # include & lt; stdio.h> 
#include
Int main ()
{
Float x;
Char g;
Scanf_s (" % f ", & amp; X);
Int y=x/10;
The switch (y)
{
Case 0:
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:
G='E';
break;

Case 6:
G='D';
break;

Case 7:
G='C';
break;

Case 8:
G='B';
break;

Case 9:
Case 10:
G='A';
break;

Default:
Printf (" Not support! \n");
break;
/*
Case '0' :
Case '1' :
Case '2' :
Case '3' :
Case '4' :
Case '5' : g='E'; break;
Case '6' : g='D'; break;
Case '7' : g='C'. break;
Case '8' : g='B'; break;
Case '9' :
Case '10' : g='A';
*/
}
Printf (" % % d c, g, y);
return 0;
}

For your reference ~

The original poster should be is not clear the difference between the '1' and 1,
X/10, when x is less than 100 data, x/10 was between 0 ~ 10 data, and '1' is a character, and the corresponding decimal is 48

CodePudding user response:

Thank you, problem solved.
  • Related