C++ Help please!

September 29, 2010 at 19:06:20
Specs: Macintosh
So I am new at C++ and here is my code. Everything works except the last part. I need to display the grade after punching in the corresponding letter. and if the grade is an "I" or an incomplete the entire midterm grade has to be "incomplete" with a note saying please see your advisor. the last part keeps giving me the first grade of 95 no matter what letter i punch in. any ideas?

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
using namespace std;


int main (void)
{

double homeworkgrade1,homeworkgrade2,homeworkgrade3,homeworkgrade4,homeworkgrade5;
double homeworkgrade6,homeworkgrade7,homeworkgrade8,homeworkgrade9,homeworkgrade10;
double homeworktotal;
double homeworkpercent;
double homeworkpercent1;

cout<<"Enter your grade for homework grade1 out of 5 points:";
cin>>homeworkgrade1;
cout<<"Enter your grade for homework grade2 out of 5 points:";
cin>>homeworkgrade2;
cout<<"Enter your grade for homework grade3 out of 5 points:";
cin>>homeworkgrade3;
cout<<"Enter your grade for homework grade4 out of 5 points:";
cin>>homeworkgrade4;
cout<<"Enter your grade for homework grade5 out of 5 points:";
cin>>homeworkgrade5;
cout<<"Enter your grade for homework grade6 out of 5 points:";
cin>>homeworkgrade6;
cout<<"Enter your grade for homework grade7 out of 5 points:";
cin>>homeworkgrade7;
cout<<"Enter your grade for homework grade8 out of 5 points:";
cin>>homeworkgrade8;
cout<<"Enter your grade for homework grade9 out of 5 points:";
cin>>homeworkgrade9;
cout<<"Enter your grade for homework grade10 out of 5 points:";
cin>>homeworkgrade10;

homeworktotal= homeworkgrade1+homeworkgrade2+homeworkgrade3+homeworkgrade4+homeworkgrade5+homeworkgrade6+homeworkgrade7+homeworkgrade8+homeworkgrade9+homeworkgrade10;
homeworkpercent=homeworktotal/50;
homeworkpercent1=((homeworkpercent*.15)*100);

cout<<"Out of a total of 15% you have received:"<<homeworkpercent1<<endl;

double labgrade1;
double labgrade2;
double labgrade3;
double labgrade4;
double labgrade;
double total;
double finallabpercentage;

cout<< "Enter your grade for lab 1 out of 10 points:";
cin>> labgrade1;
cout<< "Enter your grade for lab 2 out of 10 points : ";
cin>> labgrade2;
cout<< "Enter your grade for lab 3 out of 10 points:";
cin>> labgrade3;
cout<< "Enter your grade for lab 4 out of 10 points: ";
cin>> labgrade4;

total= labgrade1 + labgrade2 + labgrade3 + labgrade4;//the sum of all the lab grades
labgrade =((total/40)*100);
finallabpercentage= labgrade*.35;

cout<<"Out of a total of 35% you have received:"<<finallabpercentage<<endl;

char midtermproject;//The output of the midterm project will be a character
double midtermgradevalue;//will be a double variable
char incomplete;

cout<< "Enter your grade for the midterm project use capital or lower case";
cin>> midtermproject;
if(midtermproject=='a'|| 'A') midtermgradevalue=95;
else
if( midtermproject== 'b' || 'B') midtermgradevalue=85;
else
if (midtermproject== 'c' || 'C') midtermgradevalue=75;
else
if (midtermproject== 'd' || 'D') midtermgradevalue=65;
else
if (midtermproject== 'f' || 'F') midtermgradevalue=55;
else
if{midtermgradevalue== 'i' || 'I'midtermgradevalue= 0;

cout<<"Please see your advisor about your incomplete"<<endl;}

cout<<"Midtermgrade is:"<<midtermgradevalue<<endl;


return 0;
}


See More: C++ Help please!

Report •

#1
September 30, 2010 at 08:11:02
(midtermproject=='a'|| 'A') will always evaluate as true, because 'A' is not 0. Rewrite as:
(midtermproject=='a'|| midtermproject=='A')
Or better yet, convert the input into either upper or lower case and do only half the number of equality checks.

Report •
Related Solutions


Ask Question