Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

c++ doubt, need help with debugging

Status
Not open for further replies.

joe1986

Full Member level 4
Joined
Jan 25, 2008
Messages
207
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
2,946
c++ doubt

i have written a program to accept input from the
user and calculate grades (both numeric and letter) for an English, math, or
science student. but when i compile it there is no error,but i'm not able to enter the mark's, because when i type yes, i get a different output, can anyone please tell me what's wrong in the program???



// to calculate many students grade
#include <iostream>
#include <string>
main ()
{
using namespace std;

int midtermgrade=0,finalexaminationgrade=0,researchgrade=0,presentationgrade=0,i;
const double ENG_MIDTERM_PER = .25,ENG_FINALEXAMINATION_PER =.25,ENG_RESEARCH_PER = .30,ENG_PRESENTATION_PER = .20,MATH_MIDTERM_PERCENTAGE = .5F,MATH_FINALEXAM_PERCENTAGE = .50,SCIENCE_MIDTERM_PERCENTAGE = .40,SCIENCE_FINALEXAM_PERCENTAGE = .40,SCIENCE_RESEARCH_PERCENTAGE = .20;
float FINALGRADE=0;
char FINALLETTERGRADE;
char reply [256];
string moregradestocalculate;
// What type of student are we calculating?
cout << "DO YOU WANNA CALCULATE A GRADE??";
cin >> moregradestocalculate;
cout << "ENTER THE STUDENT TYPE (1=ENGLISH,2=MATH,3=SCIENCE): ";
cin.getline(reply,256);
for(i=0;i<moregradestocalculate.length();i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}

while(moregradestocalculate=="YES")
{
if (strlen(reply) == 0) // if key pressed is 0 or if enter is pressed
{
cout << "You must select a Student Type";return 1;
}

if((atoi(reply)<1) || (atoi(reply)>3)) // if no pressed is less than 0 or greater than 3.
{
cout <<reply << "-:NOT A VALID STUDENT TYPE";return 1;

}

switch(atoi(reply))
{
case 1:
cout << "ENTER midtermarks: ";
cin.getline(reply,256);
midtermgrade=atoi(reply);
cout << "ENTER finalexaminationgrade: ";
cin.getline(reply,256);
finalexaminationgrade=atoi(reply);
cout << "ENTER researchgrade: ";
cin.getline(reply,256);
researchgrade=atoi(reply);
cout << "ENTER presentationgrade: ";
cin.getline(reply,256);
presentationgrade=atoi(reply);
FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade))*4;

if(FINALGRADE>=93)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE==85 && FINALGRADE<93)
FINALLETTERGRADE ='B';
else
if(FINALGRADE==78 && FINALGRADE<85)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE==70 && FINALGRADE<7Cool
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<=70)
FINALLETTERGRADE = 'F';
cout << endl << "******ENGLISH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "presentationgrade is " << presentationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;


case 2:
cout <<"ENTER midtermgrade: ";
cin.getline(reply,256);
midtermgrade=atoi(reply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(reply,256);
finalexaminationgrade=atoi(reply);

FINALGRADE=((MATH_MIDTERM_PERCENTAGE*midtermgrade)+(MATH_FINALEXAM_PERCENTAGE*finalexaminationgrade))*2;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90&&FINALGRADE>=83)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<83 && FINALGRADE>=76)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<76 && FINALGRADE>=65)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE>=65)
FINALLETTERGRADE = 'F';

cout << endl << "******MATH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 3:
cout <<"ENTER midtermgrade: ";
cin.getline(reply,256);
midtermgrade=atoi(reply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(reply,256);
finalexaminationgrade=atoi(reply);
cout <<"ENTER researchgrade: ";
cin.getline(reply,256);
researchgrade=atoi(reply);

FINALGRADE=((SCIENCE_MIDTERM_PERCENTAGE*midtermgrade)+(SCIENCE_FINALEXAM_PERCENTAGE*finalexaminationgrade)+(SCIENCE_RESEARCH_PERCENTAGE*researchgrade))*3;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90 && FINALGRADE>=80)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<80 && FINALGRADE>=70)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<70 && FINALGRADE>=60)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<60)
FINALLETTERGRADE = 'F';

cout <<endl << "******SCIENCE STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

default:
cout << "NOT A VALID STUDENT TYPE!:-";
}

cout << "DO YOU WISH TO CALCULATE MORE GRADES??";
cin >> moregradestocalculate;
for(i=0;i<moregradestocalculate.length();i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}
}
cout << "THANKS FOR USING THE GRADE CALCULATION PROJECT!!!!";
return 0;
}
 

DrBob13

Full Member level 2
Joined
Mar 25, 2008
Messages
143
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Location
UK
Activity points
2,708
Re: c++ doubt

Hi Joe1986,
This will give you a start I hope, it seem to run OK on VisualC 6. You are mixing standard strings with char strings and the compiler does not seem to like it. You also missed a break statement out of your switch function.

// to calculate many students grade
#include <iostream>
#include <string>
using namespace std;
main ()
{

int midtermgrade=0,finalexaminationgrade=0,researchgrade=0,presentationgrade=0,i;
const double ENG_MIDTERM_PER = .25,ENG_FINALEXAMINATION_PER =.25,ENG_RESEARCH_PER = .30,ENG_PRESENTATION_PER = .20,MATH_MIDTERM_PERCENTAGE = .5F,MATH_FINALEXAM_PERCENTAGE = .50,SCIENCE_MIDTERM_PERCENTAGE = .40,SCIENCE_FINALEXAM_PERCENTAGE = .40,SCIENCE_RESEARCH_PERCENTAGE = .20;
float FINALGRADE=0;
char FINALLETTERGRADE;
char cReply[256];
char moregradestocalculate[256];
// What type of student are we calculating?
cout << "DO YOU WANNA CALCULATE A GRADE??";
//cin >> moregradestocalculate;
cin.getline(moregradestocalculate,256);
cout << "ENTER THE STUDENT TYPE (1=ENGLISH,2=MATH,3=SCIENCE): ";
cin.getline(cReply,256);
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}

while(strcmp(moregradestocalculate,"YES") == 0)
{
if (strlen(cReply) == 0) // if key pressed is 0 or if enter is pressed
{
cout << "You must select a Student Type";return 1;
}

if((atoi(cReply)<1) || (atoi(cReply)>3)) // if no pressed is less than 0 or greater than 3.
{
cout <<cReply << "-:NOT A VALID STUDENT TYPE";return 1;

}

switch(atoi(cReply))
{
case 1:
cout << "ENTER midtermarks: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout << "ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout << "ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);
cout << "ENTER presentationgrade: ";
cin.getline(cReply,256);
presentationgrade=atoi(cReply);
FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade))*4;

if(FINALGRADE>=93)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE==85 && FINALGRADE<93)
FINALLETTERGRADE ='B';
else
if(FINALGRADE==78 && FINALGRADE<85)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE==70 && FINALGRADE<70)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<=70)
FINALLETTERGRADE = 'F';
cout << endl << "******ENGLISH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "presentationgrade is " << presentationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 2:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);

FINALGRADE=((MATH_MIDTERM_PERCENTAGE*midtermgrade)+(MATH_FINALEXAM_PERCENTAGE*finalexaminationgrade))*2;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90&&FINALGRADE>=83)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<83 && FINALGRADE>=76)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<76 && FINALGRADE>=65)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE>=65)
FINALLETTERGRADE = 'F';

cout << endl << "******MATH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 3:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout <<"ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);

FINALGRADE=((SCIENCE_MIDTERM_PERCENTAGE*midtermgrade)+(SCIENCE_FINALEXAM_PERCENTAGE*finalexaminationgrade)+(SCIENCE_RESEARCH_PERCENTAGE*researchgrade))*3;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90 && FINALGRADE>=80)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<80 && FINALGRADE>=70)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<70 && FINALGRADE>=60)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<60)
FINALLETTERGRADE = 'F';

cout <<endl << "******SCIENCE STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

default:
cout << "NOT A VALID STUDENT TYPE!:-";
}

cout << "DO YOU WISH TO CALCULATE MORE GRADES??";
cin >> moregradestocalculate;
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}
}

cout << "THANKS FOR USING THE GRADE CALCULATION PROJECT!!!!";

return 0;
}

Cheers
Bob
 

    joe1986

    Points: 2
    Helpful Answer Positive Rating

joe1986

Full Member level 4
Joined
Jan 25, 2008
Messages
207
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
2,946
Re: c++ doubt

thanks a lot for your help..............there's one more problem ,after the grade gets calculated, when i need to calculate another grade if i press "yes" the cursor get's freezed.......................i tried adding a while loop at the end of the code but no success............is there a way i can make the code calculate more than one grade.............i'll explain the logic
Once the grade get's calculated a question is asked "do you wanna calculate more grades" if yes your again asked what type of student if no "THANKS FOR USING THE GRADE CALCULATION PROJECT!!!!"


// to calculate many students grade
#include <iostream>
#include <string>
using namespace std;
main ()
{

int midtermgrade=0,finalexaminationgrade=0,researchgrade=0,presentationgrade=0,i;
const double ENG_MIDTERM_PER = .25,ENG_FINALEXAMINATION_PER =.25,ENG_RESEARCH_PER = .30,ENG_PRESENTATION_PER = .20,MATH_MIDTERM_PERCENTAGE = .5F,MATH_FINALEXAM_PERCENTAGE = .50,SCIENCE_MIDTERM_PERCENTAGE = .40,SCIENCE_FINALEXAM_PERCENTAGE = .40,SCIENCE_RESEARCH_PERCENTAGE = .20;
float FINALGRADE=0;
char FINALLETTERGRADE;
char cReply[256];
char moregradestocalculate[256];
// What type of student are we calculating?
cout << "DO YOU WANNA CALCULATE A GRADE??";
cin.getline(moregradestocalculate,256);
cout << "ENTER THE STUDENT TYPE (1=ENGLISH,2=MATH,3=SCIENCE): ";
cin.getline(cReply,256);
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}


while(strcmp(moregradestocalculate,"YES") == 0)
{

if (strlen(cReply) == 0) // if key pressed is 0 or if enter is pressed
{
cout << "You must select a Student Type";return 1;
}

if((atoi(cReply)<1) || (atoi(cReply)>3)) // if no pressed is less than 0 or greater than 3.
{
cout <<cReply << "-:NOT A VALID STUDENT TYPE";return 1;

}

switch(atoi(cReply))
{
case 1:
cout << "ENTER midtermarks: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout << "ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout << "ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);
cout << "ENTER presentationgrade: ";
cin.getline(cReply,256);
presentationgrade=atoi(cReply);
FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade))*4;

if(FINALGRADE>=93)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE==85 && FINALGRADE<93)
FINALLETTERGRADE ='B';
else
if(FINALGRADE==78 && FINALGRADE<85)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE==70 && FINALGRADE<70)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<=70)
FINALLETTERGRADE = 'F';
cout << endl << "******ENGLISH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "presentationgrade is " << presentationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 2:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);

FINALGRADE=((MATH_MIDTERM_PERCENTAGE*midtermgrade)+(MATH_FINALEXAM_PERCENTAGE*finalexaminationgrade))*2;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90&&FINALGRADE>=83)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<83 && FINALGRADE>=76)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<76 && FINALGRADE>=65)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE>=65)
FINALLETTERGRADE = 'F';

cout << endl << "******MATH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 3:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout <<"ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);

FINALGRADE=((SCIENCE_MIDTERM_PERCENTAGE*midtermgrade)+(SCIENCE_FINALEXAM_PERCENTAGE*finalexaminationgrade)+(SCIENCE_RESEARCH_PERCENTAGE*researchgrade))*3;
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90 && FINALGRADE>=80)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<80 && FINALGRADE>=70)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<70 && FINALGRADE>=60)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<60)
FINALLETTERGRADE = 'F';

cout <<endl << "******SCIENCE STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

default:
cout << "NOT A VALID STUDENT TYPE!:-";
}
cout << "DO YOU WISH TO CALCULATE MORE GRADES??"; // CALCULATE MORE GRADES
while(strcmp(moregradestocalculate,"YES") == 0)
{
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}
}
}
cout << "THANKS FOR USING THE GRADE CALCULATION PROJECT!!!!";

return 0;
}
 

DrBob13

Full Member level 2
Joined
Mar 25, 2008
Messages
143
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Location
UK
Activity points
2,708
Re: c++ doubt

Hi Joe,
I think this will do what you want now. I fixed a few othere bugs in your calc routines, better check it gives the answers you expect but I think its OK now.

// to calculate many students grade
#include <iostream>
#include <string>
using namespace std;
main ()
{

int midtermgrade=0,finalexaminationgrade=0,researchgrade=0,presentationgrade=0,i;
const double ENG_MIDTERM_PER = .25,ENG_FINALEXAMINATION_PER =.25,ENG_RESEARCH_PER = .30,ENG_PRESENTATION_PER = .20,MATH_MIDTERM_PERCENTAGE = .50,MATH_FINALEXAM_PERCENTAGE = .50,SCIENCE_MIDTERM_PERCENTAGE = .40,SCIENCE_FINALEXAM_PERCENTAGE = .40,SCIENCE_RESEARCH_PERCENTAGE = .20;
float FINALGRADE=0;
char FINALLETTERGRADE;
char cReply[256];
char moregradestocalculate[256];
// What type of student are we calculating?
cout << "DO YOU WANNA CALCULATE A GRADE??";
cin.getline(moregradestocalculate,256);
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}
while(strcmp(moregradestocalculate,"YES") == 0)
{
cout << "ENTER THE STUDENT TYPE (1=ENGLISH,2=MATH,3=SCIENCE): ";
cin.getline(cReply,256);
if (strlen(cReply) == 0) // if key pressed is 0 or if enter is pressed
{
cout << "You must select a Student Type";return 1;
}

if((atoi(cReply)<1) || (atoi(cReply)>3)) // if no pressed is less than 0 or greater than 3.
{
cout <<cReply << "-:NOT A VALID STUDENT TYPE";return 1;

}

switch(atoi(cReply))
{
case 1:
cout << "ENTER midtermarks: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout << "ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout << "ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);
cout << "ENTER presentationgrade: ";
cin.getline(cReply,256);
presentationgrade=atoi(cReply);
FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade));

if(FINALGRADE>=93)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE>=85 && FINALGRADE<93)
FINALLETTERGRADE ='B';
else
if(FINALGRADE>=78 && FINALGRADE<85)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE>=70 && FINALGRADE< 78 )
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<=70)
FINALLETTERGRADE = 'F';
cout << endl << "******ENGLISH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "presentationgrade is " << presentationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 2:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);

FINALGRADE=((MATH_MIDTERM_PERCENTAGE*midtermgrade)+(MATH_FINALEXAM_PERCENTAGE*finalexaminationgrade));
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90&&FINALGRADE>=83)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<83 && FINALGRADE>=76)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<76 && FINALGRADE>=65)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<=65)
FINALLETTERGRADE = 'F';

cout << endl << "******MATH STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

case 3:
cout <<"ENTER midtermgrade: ";
cin.getline(cReply,256);
midtermgrade=atoi(cReply);
cout <<"ENTER finalexaminationgrade: ";
cin.getline(cReply,256);
finalexaminationgrade=atoi(cReply);
cout <<"ENTER researchgrade: ";
cin.getline(cReply,256);
researchgrade=atoi(cReply);

FINALGRADE=((SCIENCE_MIDTERM_PERCENTAGE*midtermgrade)+(SCIENCE_FINALEXAM_PERCENTAGE*finalexaminationgrade)+(SCIENCE_RESEARCH_PERCENTAGE*researchgrade));
if(FINALGRADE>=90)
FINALLETTERGRADE = 'A';
else
if(FINALGRADE<90 && FINALGRADE>=80)
FINALLETTERGRADE ='B';
else
if(FINALGRADE<80 && FINALGRADE>=70)
FINALLETTERGRADE = 'C';
else
if(FINALGRADE<70 && FINALGRADE>=60)
FINALLETTERGRADE = 'D';
else
if(FINALGRADE<60)
FINALLETTERGRADE = 'F';

cout <<endl << "******SCIENCE STUDENT*****" << endl;
cout << "midtermgrade is " << midtermgrade << endl;
cout << "finalexaminationgrade is " << finalexaminationgrade << endl;
cout << "researchgrade is " << researchgrade << endl;
cout << "FINALGRADE IS " << FINALGRADE << endl;
cout << "FINALLETTERGRADE IS " <<FINALLETTERGRADE << endl;
break;

default:
cout << "NOT A VALID STUDENT TYPE!:-";
}

cout << "DO YOU WISH TO CALCULATE MORE GRADES??";
cin.getline(moregradestocalculate,256);
for(i=0;i<strlen(moregradestocalculate);i++)
{
moregradestocalculate=toupper(moregradestocalculate);
}

}


cout << "THANKS FOR USING THE GRADE CALCULATION PROJECT!!!!";

return 0;
}

Cheers,
Bob.
 

    joe1986

    Points: 2
    Helpful Answer Positive Rating

joe1986

Full Member level 4
Joined
Jan 25, 2008
Messages
207
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
2,946
Re: c++ doubt

i did sum modification in the formula and the grade's are gttin calculated perfectly, here's wht i tried doin.

FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade))*4;

FINALGRADE=((MATH_MIDTERM_PERCENTAGE*midtermgrade)+(MATH_FINALEXAM_PERCENTAGE*finalexaminationgrade))*2;

FINALGRADE=((SCIENCE_MIDTERM_PERCENTAGE*midtermgrade)+(SCIENCE_FINALEXAM_PERCENTAGE*finalexaminationgrade)+(SCIENCE_RESEARCH_PERCENTAGE*researchgrade))*3;

thanks a lot for your help the code work's very well!!!!i realized the mistake i had made in the while loop!!!
 

DrBob13

Full Member level 2
Joined
Mar 25, 2008
Messages
143
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Location
UK
Activity points
2,708
Re: c++ doubt

Hi Joe,
Glad all is working ok now.
Are you sure that the *2, *3 and *4 multipliers are needed at the end of the lines because in my version it always returns an A grade with those in place as the totals come out at over 100% for any realistic scores every time and your grade analyis does the work on values from 0 t0 100% only.
Check that out and you are there I think.
Cheers
Bob.
 

    joe1986

    Points: 2
    Helpful Answer Positive Rating

joe1986

Full Member level 4
Joined
Jan 25, 2008
Messages
207
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
2,946
Re: c++ doubt

hi BOB,
i'm sorry, i forgot to tell you everything,that the program is required to calculate mark's out of 100, as you can see in the if statement the condition's are given that if it is above 93 the grade given is "A", less than 85 to 93 "B" is given and so on........... so when i was using the formula FINALGRADE =((ENG_MIDTERM_PER*midtermgrade)+(ENG_FINALEXAMINATION_PER*finalexaminationgrade)+(ENG_RESEARCH_PER*researchgrade)+(ENG_PRESENTATION_PER*presentationgrade)) i was gttin GRADE "F" for whatever values i entered because the values got added and somehow got divided (i don't know how) , i'll give you an example.....
FOR MATHS: if i entered 45 for one entry, and 45 for the next entry i used to gt 45 as the answer and the grade was "F"..........................so i tried sum variation like if there were 4 entries i tried multiplyin by 4, if there are 3 entries i tried multiplyn by 3 and for 2 entries i multiplied it by 2 and so i ended up gttin the RIGHT grades.................BUT I REALLY wanna thank you again for guiding me!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top