#include %26lt;stdio.h%26gt;
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
int main ()
{
string mystr;
double mark, gpa = 0.0;
char grade [2] = "F" ;
cout %26lt;%26lt; "What's your name? ";
getline (cin, mystr);
cout %26lt;%26lt; "nice name " %26lt;%26lt; mystr %26lt;%26lt;"\n";
cout %26lt;%26lt; "What is your grade? ";
cin %26gt;%26gt; mark;
if (mark %26gt;= 90 %26amp;%26amp; mark %26lt;= 100)
{
*grade = 'A';
gpa = 4.0;
}
else if (mark %26gt;= 85)
{
*grade = 'B';
grade[1] = '+';
gpa = 3.5;
}
else if (mark %26gt;= 80)
{
*grade = 'B';
gpa = 3.0;
}
else if (mark %26gt;= 75)
{
*grade = 'C';
grade[1] = '+';
gpa = 2.5;
}
else if (mark %26gt;= 70)
{
*grade = 'C';
gpa = 2.0;
}
else if (mark %26gt;= 60)
{
*grade = 'D';
gpa = 1.0;
}
else
{
*grade = 'F';
gpa = 0.0;
}
cout %26lt;%26lt; mystr %26lt;%26lt; " got a ";
if (*grade == 'A') cout %26lt;%26lt; 'n';
cout %26lt;%26lt; grade %26lt;%26lt; " in your class and a GPA of " %26lt;%26lt; gpa %26lt;%26lt; endl;
system("pause");
return 0;
}
How can i make this c++ program display the gpa as a decimal?? please help me! thanks so....... much?
#include %26lt;stdio.h%26gt;
int main (void)
{
char mystr[80];
double mark, gpa = 0.0;
char grade [2] = "F" ;
printf("What's your name? ");
fgetline (mystr, 80, stdin);
printf("nice name %s\n", mystr);
printf("What is your grade? ");
scanf("%d", %26amp;mark);
if (mark %26gt;= 90 %26amp;%26amp; mark %26lt;= 100)
{
*grade = 'A';
gpa = 4.0;
}
else if (mark %26gt;= 85)
{
*grade = 'B';
grade[1] = '+';
gpa = 3.5;
}
else if (mark %26gt;= 80)
{
*grade = 'B';
gpa = 3.0;
}
else if (mark %26gt;= 75)
{
*grade = 'C';
grade[1] = '+';
gpa = 2.5;
}
else if (mark %26gt;= 70)
{
*grade = 'C';
gpa = 2.0;
}
else if (mark %26gt;= 60)
{
*grade = 'D';
gpa = 1.0;
}
else
{
*grade = 'F';
gpa = 0.0;
}
printf("%s got a ", mystr);
if (*grade == 'A') putchar('n');
printf("%s in your class and a GPA of %.1f\n", grade, gpa);
system("pause");
return 0;
}
Reply:Back in my day, we had to use printf(), and walk ten miles each way... in the SNOW.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment