I need to incorporate an if else that only add points if they are good else make
them enter again. Can someone please help me with this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//This program will calculate and display student letter grade
#include <iostream>
#include <iomanip> //needed for manipulating output
#include <cmath>
#include <cstdlib>//needed to clear screen
#include <string>
using namespace std;
int main()
{
[code]
|
//Declare and initialize variables
double avg = 0;
double grade = 0;
double finalGrade = 0;
double points = 0;
double totalPoints = 0;
int numOfTest= 0;
char letterGrade;
char out1 = 'y';
char in1 = 'Y';
string fname, lname;
cout<<"Would you like to use this grading program ? <Y> or <y>"<<endl;
cout<<"OR enter <N> or <n> to exit"<<endl;
cin>>out1;
while(out1== 'Y'|| out1 =='y')//allows user to enter or exit program
{
system("cls");//clears screen
cout <<"Please enter your first name: " <<endl;
cin >>fname;//user enters name
cout <<"\nPlease enter your last name: " <<endl;
cin >>lname;
system("cls");
while(in1== 'Y' || in1== 'y')
{
cout << fname<<","<<endl;
cout<<"\nPlease enter the grade point value of the assignment:" <<endl;
cin >>points;
totalPoints = totalPoints+points;//Adds point total
numOfTest++;//adds number of grades entered
cout <<"\nPlease enter your score:"<<endl;
cin >> grade;
finalGrade = finalGrade + grade;//adds grade totals together
while(grade < 0 || grade > points)//decision making statement to determine if user entered correct values
{
cout<<fname <<" YOU ENTERED A INVALID VALUE"<<endl;
cout<<"Enter number between 0 and "<<points<<endl;
cin >> grade;
}
cout<<"Do you have another grade? <Y> or <y> yes";
cout<<"\nOr click <N> or <n> to continue to next screen"<<endl;
cin>> in1;//determines if user will leave the loop
}
avg = (finalGrade/totalPoints)*100;//Determines average
system("cls");
cout << setprecision(1);//sets decimal places
cout <<fixed<<showpoint;
cout <<fname <<" You have " <<numOfTest<< " grade(s) entered"<<endl;
cout <<" \nYour Average is: "<<avg<<"%"<<endl;
cout <<endl;
cout <<"Total Points possible: "<<totalPoints<<endl;
cout <<endl;
cout <<"Total points earned: "<<finalGrade<<endl;
cout <<endl;
if(avg <= 100.99 && avg >= 94.00)//determines grade
cout<<fname << " Your grade is a A"<<endl;
else
if(avg <= 93.99 && avg >= 90.00)
cout<<fname << " Your grade is a A-"<<endl;
else
if(avg <= 89.99 && avg >= 87.00)
cout<<fname << " Your grade is a B+"<<endl;
else
if(avg <= 86.99 && avg >= 83.00)
cout<<fname << " Your grade is a B"<<endl;
else
if(avg <= 82.99 && avg >= 80.00)
cout<<fname << " Your grade is a B-"<<endl;
else
if(avg <= 79.99 && avg >= 77.00)
cout<<fname << " Your grade is a C+"<<endl;
else
if(avg <= 76.99 && avg >= 73.00)
cout<<fname << " Your grade is a C"<<endl;
else
if(avg <= 72.99 && avg >= 70.00)
cout<<fname << " Your grade is a C-"<<endl;
else
if(avg <= 69.99 && avg >= 66.00)
cout<<fname << " Your grade is a D+"<<endl;
else
if(avg <= 65.99 && avg >= 60.00)
cout<<fname << " Your grade is a D"<<endl;
else
if(avg <= 59.99 && avg >= 0)
cout<<fname << " Your grade is a E"<<endl;
fname, lname;
avg = 0;
grade = 0;
finalGrade = 0;
points = 0;
totalPoints = 0;
letterGrade;
out1 = 'y';
in1 = 'Y';
cout<<"\nWould you like to continue to run this grading program <Y> or <y>"<<endl;
cout<<"OR enter <N> or <n> to exit"<<endl;
cin>>out1;
}
return 0;
}
[/code]