1 / 2100%
// 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 >= 90 && average <= 100)
cout << "A" << endl;
else if (average >= 80 && average < 90)
cout << "B" << endl;
else if (average >= 60 && average < 80 )
cout << "you pass" << endl;
else if (average >= 0 && average < 60)
cout << "you fail" << endl;
else cout<<"invalid input"<<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.
No output when 60 is entered
See the modified code (change (average > 60) to (average >= 60))
Exercise 2: Modify the program so that it uses an if/else statement rather
than two if statements.
if (average >= 60)
cout << "You Pass" << endl;
else
cout << "You Fail" << endl;
Exercise 3: Modify the program from Exercise 2 to allow the following
categories:
Invalid data (data above 100 and less than 0),
"A" category (90-100),
"B" category (80-89 (less than 90)),
"You Pass" category (60-79 (less than 80)),
"You Fail" category (0-59 (less than 60)).
if (average >= 90 && average <= 100)
cout << "A" << endl;
else if (average >= 80 && average < 90)
cout << "B" << endl;
else if (average >= 60 && average < 80)
cout << "you pass" << endl;
else if (average >= 0 && average < 60)
cout << "you fail" << endl;
else cout<<"invalid input"<<endl; */
Powered by TCPDF (www.tcpdf.org)
Students also viewed