Not sure what I have done wrong

ok this code does not pull up any errors in the compiler, and from what I can tell should run smoothly, but it does not. It only runs the first if statement no matter what input the user enters. I am a noob to this so please don't fuss at me for making a stupid mistake. I am using code blocks as my compiler. thanks for any help :)


#include <iostream>
#include <cmath>
#include<ctime>
#include<cstdlib>
using namespace std;

int main()
{
int exit;
int q;
do {
cout << "Hello, welcome to your simple arithmetic tutor" <<endl;
cout << "You have four choices, they are as follows:" <<endl;
cout << "[A] for adddition, [D] for division, [M] for multiplication,\nor [S] for subtraction" <<endl;
cout << "Please make your selection and hit enter\n\n" <<endl;
char choice;
cin >> choice;

if (choice == 'A'||'a')
{
cout << "I will give you two numbers, you add them for me \nthen enter the sum and we will see if you are correct.\n\nYou have 3 tries.\n\n";
srand((unsigned) time(0));
int retry;
while (retry!=1) {
int rand1 = rand() % 101;
int rand2 = rand() % 101;
int answer = rand1 + rand2;
int uranswer;
int tries = 3;
do {
cout <<"Add " << rand1 <<" and "<< rand2 << endl;
cin >> uranswer;

if (uranswer==answer){
cout<< "Congratulations you solved the problem!" <<endl;
cout<<"Please enter exit to end the program"<<endl;
cin>>exit;
tries = 0;
return 0;
}
else{
cout<< "Wrong! Please try again\n" << endl;
tries = tries-1;
}
} while (tries!=0);

cout<< "Oh wait, that was your last try, too bad, you could not solve the problem, keep practicing.\n\n"<<endl;
cout<< "By the way, the correct answer was "<<answer<<endl;
cout<< "To try again please enter 2, to give up please enter 1.\n\n"<<endl;
cin>> retry;
}

return 0;
}

else if (choice == 'D'||'d')
{
cout << "I will give you two numbers, you divide the first by the second \nthen enter them and we will see if you are correct.\nRound to the hundredth place.\n\nYou have 3 tries.\n\n";
srand((unsigned) time(0));
int retry;
while (retry!=1) {
double rand1 = rand() % 101;
double rand2 = rand() % 11;
double answer = ((rand1 / rand2)*100+0.5)/100;
double uranswer;
int tries = 3;
do {
cout <<"Divide " << rand1 <<" by "<< rand2 << endl;
cin >> uranswer;

if (uranswer==answer){
cout<< "Congratulations you solved the problem!" <<endl;
cout<<"Please enter exit to end the program"<<endl;
cin>>exit;
tries = 0;
return 0;
}
else{
cout<< "Wrong! Please try again\n" << endl;
tries = tries-1;
}
} while (tries!=0);

cout<< "Oh wait, that was your last try, too bad, you could not solve the problem, keep practicing.\n\n"<<endl;
cout<< "By the way, the correct answer was "<<answer<<endl;
cout<< "To try again please enter 2, to give up please enter 1.\n\n"<<endl;
cin>> retry;
}

return 0;
}


else if (choice == 'M'||'m')
{
cout << "I will give you two numbers, you multiply them \nthen enter your answer and we will see if you are correct.\n\nYou have 3 tries.\n\n";
srand((unsigned) time(0));
int retry;
while (retry!=1){
double rand1 = rand() % 13;
double rand2 = rand() % 13;
double answer = (rand1 * rand2);
double uranswer;
int tries = 3;
do {
cout <<"Multiply " << rand1 <<" by "<< rand2 << endl;
cin >> uranswer;

if (uranswer==answer){
cout<< "Congratulations you solved the problem!" <<endl;
cout<<"Please enter exit to end the program"<<endl;
cin>>exit;
tries = 0;
return 0;
}
else{
cout<< "Wrong! Please try again\n" << endl;
tries = tries-1;
}
} while (tries!=0);

cout<< "Oh wait, that was your last try, too bad, you could not solve the problem, keep practicing.\n\n"<<endl;
cout<< "By the way, the correct answer was "<<answer<<endl;
cout<< "To try again please enter 2, to give up please enter 1.\n\n"<<endl;
cin>> retry;
}

return 0;
}


else if (choice == 'S'||'s')
{
cout << "I will give you two numbers, you subtract the first by the second \nthen enter the answer and we will see if you are correct.\nRound to the hundredth place.\n\nYou have 3 tries.\n\n";
srand((unsigned) time(0));
int retry;
while (retry!=1){
double rand1 = rand() % 101;
double rand2 = rand() % 101;
double answer = (rand1 - rand2);
double uranswer;
int tries = 3;
do {
cout <<"Subtract " << rand1 <<" by "<< rand2 << endl;
cin >> uranswer;

if (uranswer==answer){
cout<< "Congratulations you solved the problem!" <<endl;
cout<<"Please enter exit to end the program"<<endl;
cin>>exit;
tries = 0;
return 0;
}
else{
cout<< "Wrong! Please try again\n" << endl;
tries = tries-1;
}
} while (tries!=0);

cout<< "Oh wait, that was your last try, too bad, you could not solve the problem, keep practicing.\n\n"<<endl;
cout<< "By the way, the correct answer was "<<answer<<endl;
cout<< "To try again please enter 2, to give up please enter 1.\n\n"<<endl;
cin>> retry;
}

return 0;
}

else { cout<< "incorrect input"<<endl;
}

cout<< "To exit the program hit 1, to restart the program hit 2"<<endl;
cin>> q;
}while (q!=1);

return 0;
}
You can't do if statements like this.
if (choice == 'A'||'a')

You need to separate them out so it compares each choice individually, like this.
if (choice == 'A'||choice == 'a')
Correct.

This statement:
if (choice == 'A'||'a')
has the same meaning as this:
if ( (choice == 'A') || ('a'))
Notice the second condition, ('a'), this is evaluated according to the rule that zero is considered false, anything which is non-zero is considered true.

Hence regardless of whether this (choice == 'A') is true or false, because the second part is always true, the complete test is always true.
@James2250 & Chervil, thanks so much, it works as planned now :)
Topic archived. No new replies allowed.