Name: 3. (20 pts) Given a variable named grade holding a student\'s exam score,
ID: 3587226 • Letter: N
Question
Name: 3. (20 pts) Given a variable named grade holding a student's exam score, write a code to print if the student passed or failed. Assume that the variables are declared and w only the necessary statement (s) for each situation below. You can use additi variables if you want. (a) Presume that the exam score, grade, is a numeric score, of type int, betweeno 100, and use one or more if or if-else statements. A failing grade is a 50 or less. Ass that the variable grade is declared and write only the if or else statemen necessary to print if the exam score is a passing or failing grade (b) Presume that the exam score, grade, is a letter grade, of type char, with the values: A, B, C, D, or F, and use a switch-case statement. A grade of D or F course. Assume that the variable grade is declared and write only the swit statement necessary to print if the exam score is a passing or failing grade.Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// your code goes here
int grade;
printf("Enter the grade");
scanf("%d",&grade);
if(grade>=50)
printf(" Passed");
else if(grade<50)
printf(" Failed");
return 0;
}
Output:
Enter the grade:60
Passed
b)
#include <iostream>
using namespace std;
int main() {
// your code goes here
char grade;
printf("Enter the grade");
scanf("%c",&grade);
switch(grade)
{
case 'A':
printf("Passed");
break;
case 'B':
printf("Passed");
break;
case 'C':
printf("Passed");
break;
case 'D':
printf("Failed");
break;
case 'F':
printf("Failed");
break;
default :
exit;
}
return 0;
}
Output:
Enter the Grade: D
Failed
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.