//examgrade.cpp
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
int main()
{
int passed = 0; //number of passes
int failures = 0; //number of failures
int studentCounter = 0; //student counter
int result; //one exam result (1=pass, 2=fail)
while (result != -1)
{
//prompt user for input & obtain val.
cout << "Enter result (1=pass, 2=fail, -1=done): ";
cin >> result; //input result
//counters
if (result == 1)
passed = passed + 1;
elseif (result == 2)
failures = failures + 1;
}
cout << "The number of students that passed were: " << passed << "\nThe number of students that failed were: " << failures << endl;
cout << "There was a total of: " << studentCounter << " students that took the test." << endl;
if (passed > 8)
cout << "Raise tuition " << endl;
}
You can increment student counter in the same block where you increment passes and failures. Just use curly braces so that the compiler knows you want to perform multiple statements.
int main()
{
int passed = 0; //number of passes
int failures = 0; //number of failures
int studentCounter = 0; //number of students
int result; //one exam result (1=pass, 2=fail)
while (result != -1)
{
//prompt user for input & obtain val.
cout << "Enter result (1=pass, 2=fail, -1=done): ";
cin >> result; //input result
//counters
if (result == 1)
{
passed = passed + 1;
studentCounter++;
}
elseif (result == 2)
{
failures = failures + 1;
studentCounter++;
}
I'm getting a Syntax (parse) error at or before end of file. Where else am I suppose to enter a brace?
EDIT: I only ask because putting a brace at the end of the while will just end the statement, won't it?