c++, my numbers are not adding righ

Score
0
Vote Up
mikealis February 13, 2004 at 13:54:32 Pacific
Specs: windows xp, ?

My numbers are not adding correctly...does this look right?

#include<iomanip>
#include<iostream>
#include<conio.h>
#include<fstream>

using namespace std;

void main ()
{

cout<<left<<setw(60)<<setfill('*')<<'*'<<endl;
cout<<"IT 210 Business Applications with C++"<<endl;
cout<<"Programmer: Michael Sawyer"<<endl;
cout<<"February 13, 2004"<<endl;
cout<<"Program Assignment 1: Sum Scores and Assign Letter Grade"<<endl;
cout<<left<<setw(60)<<setfill('*')<<'*'<<endl<<endl;

char grade, flag='y';
string first_name, last_name ;
float avg, pavg, tavg ;
int score, pgrade1=0, pgrade2=0, pgrade3=0, tgrade=0, tgrade2=0, tgrade3=0, total;

pavg=(pgrade1+pgrade2+pgrade3)/3;
tavg=(tgrade1+tgrade2+tgrade3)/3;
total= pgrade1+pgrade2+pgrade3+tgrade1+tgrade2+tgrade3;
avg=(pavg+tavg)/2;

if (avg>=90) grade='A';
else if (avg>=80) grade='B';
else if (avg>=70) grade='C';
else grade='F';

while (flag=='y' || flag=='Y')
{
cout<<"Welcome!"<<endl<<endl;
cout<<"Please enter the student's first and last name: ";
cin>>first_name>>last_name;
cout<<endl;
cout<<"Please enter the student's three program scores"<<endl;
cout<<"Each score must be an integer between 0 and 100"<<endl;
cin>>pgrade1>>pgrade2>>pgrade3;
cout<<endl;
cout<<"The scores you entered were "<<pgrade1<<' '<<pgrade2<<' '<<pgrade3
<<endl;
cout<<endl;
cout<<"Please enter the student's three test scores"<<endl;
cout<<"Each score must be an integer between 0 and 100"<<endl;
cin>>tgrade1>>tgrade2>>tgrade3;
cout<<endl;
cout<<"The scores you entered were "<<tgrade1<<' '<<tgrade2<<' '<<tgrade3<<endl;
cout<<endl;

cout<<left<<setw(50)<<setfill('=')<<'='<<setfill(' ')<<endl;
cout<<left<<setw(20)<<"STUDENT NAME"<<setw(20)<<"COURSE PERFORMANCE"<<endl;
cout<<left<<setw(50)<<setfill('-')<<'-'<<setfill(' ')<<endl<<endl;
cout<<left<<setw(20)<<first_name+' '+last_name<<setw(20)<<setfill('.')
<<"Total Points Earned"<<total<<endl;
cout<<setw(20)<<setfill(' ')<<' '<<setw(20)<<setfill('.')<<"Average Program Score"
<<pavg<<setfill(' ')<<endl;
cout<<setw(20)<<setfill(' ')<<' '<<setw(20)<<setfill('.')<<"Average Test Score"
<<tavg<<setfill(' ')<<endl;
cout<<setw(20)<<setfill(' ')<<' '<<setw(20)<<setfill('.')<<"Course Grade"
<<grade<<setfill(' ')<<endl<<endl;
cout<<left<<setw(50)<<setfill('=')<<'='<<setfill(' ')<<endl<<endl;

cout<<"Enter y to calculate another grade or n to exit"<<endl;
cin>>flag;
}//end of while

cout<<"Press any key to continue"<<endl<<endl;
getch();
}//end of main



Reply ↓  Report •


#1
Vote Down
Score
0
Vote Up
February 13, 2004 at 20:37:44 Pacific

Ummm...

You are getting all zeros and Fs for output, correct??

It's because you are doing your calculations:

pavg=(pgrade1+pgrade2+pgrade3)/3;
tavg=(tgrade1+tgrade2+tgrade3)/3;
total= pgrade1+pgrade2+pgrade3+tgrade1+tgrade2+tgrade3;
avg=(pavg+tavg)/2;

if (avg>=90) grade='A';
else if (avg>=80) grade='B';
else if (avg>=70) grade='C';
else grade='F';


before (outside) the loop and before any input. The above code should be after the following lines of code:

cout<<"The scores you entered were "<<tgrade1<<' '<<tgrade2<<' '<<tgrade3<<endl;
cout<<endl;



Reply ↓  Report •
Reply to Message Icon Start New Discussion
Related Posts

« C comparing array A is su... c programing »

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.

Ask the Community!
Describe your Problem
Example: Hard Drive Not Detected on My PC