HOW TO ADD IF ELSE STATEMENTS???

closed account (z6f9LyTq)
So far I have:
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <math.h>


int main ()
{

int grade;
int numgrades;
int total=0;
double average;



cout << "Enter the number of tests:" << endl;
cin >> numgrades;



{cout << " " << endl;
for (int x = 0; x<numgrades; x++)
{
cout << "Test #" << x+1 << ": ";
cin >> grade;
total+=grade;
}
}

cout << " " << endl;

cout << "Number of tests: " << numgrades << endl;
cout << "Total: " << total;
average = total/numgrades;
cout << "\nAverage of tests: " << average;



return 0;

}


------


Now I need the if-else statements for if the teacher wants to add a certain comment per particular grade range. Say if the range was from 90-100, the teacher should say something like "You get an A" or if it's something else (80 to 90) it should be "You get a B" and so on.

Please helP????
closed account (j3Rz8vqX)
1
2
if (x == 100)
  cout << "x is 100";

http://www.cplusplus.com/doc/tutorial/control/

Your code in the code brackets, with correct c++ headers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;
int main ()
{
    int grade;
    int numgrades;
    int total=0;
    double average;
    cout << "Enter the number of tests:" << endl;
    cin >> numgrades;
    //<<---------------------------------INSERT IF CONDITION HERE---------------
    {
        cout << " " << endl;
        for (int x = 0; x<numgrades; x++)
        {
            cout << "Test #" << x+1 << ": ";
            cin >> grade;
            total+=grade;
        }
    }
    cout << " " << endl;
    cout << "Number of tests: " << numgrades << endl;
    cout << "Total: " << total;
    average = total/numgrades;
    cout << "\nAverage of tests: " << average;
    return 0;
}
Topic archived. No new replies allowed.