ok guys, im trying to code a grade calculator for my programming class and my if/else if block is screwing me over because it equates y/n to elicit the same response.
every time i run the program and, say i put n to answer the if else statement, it will tell the program that both conditions were satisfied and idk it's screwing me over
Here's my code
using namespace std;
//declare all grade variables
cout << "Welcome to the Grade Calculator!" << endl;
cout << "Can I have your homework grades in order from homework's 1-7?" << endl;
cin >> homework1 >> homework2 >> homework3 >> homework4 >> homework5 >> homework6 >> homework7;
cout << "Can I have your recitation grades in order from recitation's 1-7?" << endl;
cin >> recitation1 >> recitation2 >> recitation3 >> recitation4 >> recitation5 >> recitation6;
cout << "Can I have your test grades for miderm 1 and midterm 2 in that order?" << endl;
cin >> midterm1 >> midterm2;
cout << "Can I have the grade of your final exam?" << endl;
cin >> finalexam;
//declaring possible answers to extracred question
char Y, y, N, n;
//I will declare your average variables
int homework_avg, test_avg, course_avg;
cout << "\nIs there any extra credit to add in? (Y or N) --> ";
cin >> answ1;
I will focus on what you are asking. The one thing that caught my attention is that your variable answ1 should be a char data type and not a bool.
why? i thought boolean variables stored true or false values. and i also thought that you needed that for if/else if blocks.
my main issue is with the if/else if block that asks for extra credit.
By the way, when i switch answ1 to char type it reads any response to "Is there any extra credit to add in? (Y or N) ==>" as an invalid option and it subsequently exits the program.
Oh and another thing are you allowed to put input and variable initialization within the if/else if block because I've never seen other people do this even though I don't see why you wouldn't be able to?