hello, can somebody assist me with my code,i have been reading it for days and i still cant figure out whats wrong with it, it supposed to be a simple program taking in numbers and doing different operations like addition, subtraction, division, and multiplication, nothing mentally challenging they are physics formulas but its very basic in general.IF U CAN HELP ME IT WOULD BE A BLESSING
The trouble is mostly with the brackets thats all.
At first look, the problem seems to be that you're using int as the main type, when double or at least float are better suited for physics calculations.
//...
int n;
cin>>n;
//...
if(n=='A'||n=='a')
//...etc
You definitely mean char n because ur inputting characters like 'a' instead of integers like 0,1,2, etc.
this also means ur going to hafta change these parts
1 2
elseif (n==1) //bad
elseif (n=='1') //acceptable
For future reference it would be much easier to keep track of all of this code if you encapsulated parts of it in functions but that's just my opinion.
For instance it's much easier to say
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void printForceForms()
{
cout<<"Force, here are the following formulas:"<<endl;
cout<<"1. Acceleration(a)=Net Force(Fnet)/Mass(m)"<<endl;
cout<<"2. Force of Friction(Ff)=Coefficient of Friction(//add micro symbol)*Normal Force(Fn)"<<endl;
cout<<"3. Force of Gravity(Fgrav)=Universal Gravitational Constant(G)*Mass1(m1)*Mass2(m2)/Radius^2(r^2)"<<endl;
//...
}
//...
if(n=='B'||n=='b')
{
cout<<"You chose B. ";
printForceForms();
}
else //etc
there are probably a lot of other things you could change too but I tend to think using lots of functions is important because it helps avoid headaches later :)
i changed all the ints into chars but i still got the same issue well sort of i can see the menus for each of the 4 abcd choices however when i want to choose a specific one it ends the program
basically u are being inconsistent with your input type...
sometimes it's a char.. sometimes it's an int... your program will need to be flexible based on the user's input.
the link Zaita provided is mostly to tell u how to avoid errors with entering the wrong data type which is important, but I think your main problem is you're not taking into account what type of input you're expecting from the user.
Zaita's link isn't going to be much help to you unless u consider that.
P.S This would be much easier to debug (and modify) if u used functions and indented morre.... just puttin that out there...