i think i get the basics it just isn't displaying. can someone help me please. my code runs once then repeats the score every time. I want it to ask me midterm and final every time and then apply the proper grade. it give me score from first time and doesnt show graade at al.
I am a beginner so if you could help i would really appreciate it. here is my code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int midterm;
int final;
cout << "please enter midterm grade: ";
cin >> midterm;
while (midterm < 0 || midterm > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
cin >> midterm;
}
cout << " please enter final grade: ";
cin >> final;
while (final < 0 || final > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. Please enter grade";
cin >> final;
}
int total;
total = final + midterm;
if (total > 360 || total <=400)
{
cout << "your letter grade is A";
}
else if (total > 320 || total< 359)
{
cout << "your letter grade is B";
}
else if (total > 280 ||total < 319)
{
cout << "your letter grade is C";
}
else if (total > 279 ||total < 241)
{
cout << "your letter grade is D";
}
else if (total < 240)
{
cout << "your letter is F";
The union of numbers that meet "total > 360 || total <=400" is every real number. You want &&, not ||. You could also simplify the conditions to not require ands or ors. If this is not the issue, please say precisely what your input is, and what is being output that's wrong.
hey ganada i made that change it didnt do anything. my code shows me midterm and final grade added together but it isnt giving me the letter that goes along with it. for intance 340 is a B. when it displays tho it onlysays 340 and no letter. also it doesnt allow me to ask question with new answer everytime. if the first score is 340 then it doesnt change or go away? i want it to ask me for mid term and ifnal score evry time then give me grade?
#include <iostream>
usingnamespace std;
int main() {
int midterm {};
int final {};
cout << "Please enter midterm grade: ";
while ((cin >> midterm) && (midterm < 0 || midterm > 200))
cout << "Please enter valid amount must be 0 or greater and 200 or less. please enter grade: ";
cout << "Please enter final grade: ";
while ((cin >> final) && (final < 0 || final > 200))
cout << "Please enter valid amount must be 0 or greater and 200 or less. Please enter grade";
constauto total {final + midterm};
if (total > 360 && total <= 400)
cout << "your letter grade is A";
elseif (total > 320 && total < 359)
cout << "your letter grade is B";
elseif (total > 280 && total < 319)
cout << "your letter grade is C";
elseif (total > 279 && total < 241)
cout << "your letter grade is D";
else
cout << "your letter is F";
}
Now you add an outer loop to process multiple grades.
Another thing to think about: In addition to changing the ||s to &&s, what happens if the total comes out to, say, exactly 360 or 359? And what error handling, if any, do you want to happen if the number entered is > 400?
colton, show your full, revised code and then I'm sure somebody will try to interpret what you wrote. Your current code doesn't even have a "-1 to stop" outer loop.
By using functions which probably comes later on you can combine the midterm and final input while loops as a single operation but this addresses your problems by the look of it.
#include <iostream>
// #include <iomanip> NOT BEING USED
usingnamespace std;
int main()
{
int midterm{0};
int final{0};
while (
(cout << "please enter midterm grade: " &&
cin >> midterm &&
midterm < 0) || midterm > 200
)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
// cin >> midterm;
}
while (
(cout << "please enter final grade: " &&
cin >> final &&
final < 0) || final > 200
)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
// cin >> final;
}
int total{0};
total = final + midterm;
char letter{'?'};
if (total >= 360) // || total <=400)
{
letter = 'A';
}
elseif (total >= 320) // || total< 359)
{
letter = 'B';
}
elseif (total >= 280) // ||total < 319)
{
letter = 'C';
}
elseif (total >=240) // 279 ||total < 241)
{
letter = 'D';
}
else // if (total < 240)
{
letter = 'F';
}
cout
<< " Your total grade is " << midterm + final << endl
<< "Your letter grade is " << letter << endl;
}
please enter midterm grade: 123
please enter final grade: 146
Your total grade is 269
Your letter grade is D
Program ended with exit code: 0