Hello this is a program to help kids with math, it is really basic.
I am having issues with the logic from line 78 to line 86.
Please help me out! :D
I used a go to statement because I became very lazy and thought it would be quicker, but now I am stuck and I really want to solve this now. Lol I thought it would be easy but turned out to be a problem.
#include <iostream>
#include <stdio.h>
usingnamespace std;
int main()
{ //WRITE DOWN VARIABLES FOR THE PROGRAM TO OUTPUT THE MENU OPTIONS.
startover:
constint additionOption=1;
constint subtractionOption=2;
constint multiplicationOption=3;
constint divisionOption=4;
double number1=0;
double number2=0;
double answer=0;
//PRINT(COUT) OUT THE MENU OPTIONS FOR USER TO READ.
cout<<"\tInput a number to select the menu option of your choice."<<endl;
cout<<"\n\n\n";
cout<<"\t1.Addition\n";
cout<<"\t2.Subtraction\n";
cout<<"\t3.Multiplication\n";
cout<<"\t4.Division\n";
// ASK USER WHICH OPTION THEY WOULD LIKE TO USE.
int choice;
cin>>choice;
switch(choice)
{
//CREATE ADDITION OPTION
case additionOption:
cout<<"Insert two numbers that will be added."<<endl;
cin>>number1;
cin>>number2;
answer= number1+number2;
cout<<"Your answer is "<<answer<<"\n";
break;
//CREATE SUBTRACTION OPTION
case subtractionOption:
cout<<"Insert two numbers that will be subtracted."<<endl;
cin>>number1;
cin>>number2;
answer= number1-number2;
cout<<"Your answer is "<<answer<<"\n";
break;
//CREATE MULTIPLICATION OPTION
case multiplicationOption:
cout<<"Insert two numbers that will be multiplied."<<endl;
cin>>number1;
cin>>number2;
answer= number1*number2;
cout<<"Your answer is "<<answer<<"\n";
break;
//CREATE DIVISION OPTION
case divisionOption:
cout<<"Insert two numbers that will be divided."<<endl;
cin>>number1;
cin>>number2;
answer=number1/number2;
cout<<"Your answer is "<<answer<<"\n";
break;
default:
cout<<"The numbers you have provided this program do not\n";
cout<<"correspond with the above menu, please try again or end program.\n"<<endl;
}
//ASK USER IF THEY WOULD LIKE TO RETRY PROGRAM
cout<<"Would you like to retry program?"<<endl;
string retry;
cin>>retry;
cin.ignore();
//IF USER REPLIES YES, THEN RETRY
if(retry=="Yes"||"yes"||"YES")
goto startover;
else
cout<<"Thank you for using the program, make sure you only use this as a last resort."<<endl;
//IF USER REPLIES NO, THANK THEM FOR USING PROGRAM/END PROGRAM.
cin.get();
return 0;
}
This was actually wrong of me.
a statement allways resolves to a true or a false.
everything that does not explicitly compare to a value is compared to be not-equal to 0
so the example above should look like if(retry == "Yes" or "yes"!=0 or "YES"!=0)
so basically these 2 are equal.
if("hello")
if("hello" != 0)
it's a bit hard to understand with pure text because the type of pure text is const char* (a pointer) so i'll make it with numbers ;)
these 2 are equal.
if(5)
if(5 != 0)