// This program prints \"You Pass\" if a student\'s average is // 60 or higher a
ID: 3759574 • Letter: #
Question
// This program prints "You Pass" if a student's average is
// 60 or higher and prints "You Fail" otherwise
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
int main()
{
float average; // holds the grade average
cout << "Input your average:" << endl;
cin >> average;
if (average > 60)
cout << "You Pass" << endl;
if (average < 60)
cout << "You Fail" << endl;
return 0;
}
Exercise 1: Run the program three times using 80, 55 and 60 for the average. What happens when you input 60 as the average? Modify the first if statement so that the program will also print “You Pass” if the average is greater than or equals 60.
Exercise 2: Modify the program so that it uses an if/else statement rather than two if statements.
Exercise 3: Modify the program from Exercise 2 to allow the following categories: Invalid data (data above 100), ‘A’ category (90–100), ‘B’ category (80–89), “You Pass” category (60–79), “You Fail” category (0–59). What will happen to your program if you enter a negative value such as -12?
Explanation / Answer
1. for 80 it prints you pass
for 60 it prints nothing
for 55 it prints you fail
2.
#include <iostream>
using namespace std;
int main()
{
float average; // holds the grade average
cout << "Input your average:" << endl;
cin >> average;
if (average >=60)
cout << "You Pass" << endl;
else{
cout << "You Fail" << endl;
}
return 0;
}
3.
#include <iostream>
using namespace std;
int main()
{
float average; // holds the grade average
cout << "Input your average:" << endl;
cin >> average;
if (average >100)
cout << "Invalid Input" << endl;
else if(average>=90){
cout << "Grade A" << endl;
}else if(average>=80){
cout << "Grade B" << endl;
}else if(average>=60){
cout << "You pass" << endl;
}else{
cout << "You fail" << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.