### Need Help on selecting functions ( would be appreicated )

i am a beginner in programming , i just want to make a program to train little kids in mathematics operations , the idea behind the code is that i want once you compile it you choose what operation the kid wants to practice based on pressing 1 , 2 , 3 & 4 ( Multiplication , addition , division , and subtraction ), and then if the answer of the result is right a " a very good" pops up , but if its wrong " please try again " until he answer it right *loop* . i tried doing it for countless hours doing void function , but i keep failing over and over .
any help in this would be really appreciated .

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110`` `````` #include #include double Multiplication(double a, double b); void addition(double a, double b,double &m); void division(double a, double b,double &d); void subtraction(double a, double b,double &s); double answer = 0 ; using namespace std; int main() { double a = (rand() % 10) + 1; double b = (rand() % 10) + 1; double i; cout<<"\n\n This is a Program to teach Elementary Students how to do Mathmatical Operations \n\n"; cout<<"\n\nPress 1 for Multiplication , 2 for addition , 3 for division ,and 4 for subtraction\n\n"; cin>>i; if(i = 1) cout<> answer; if(answer ==(a*b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a+b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a/b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a-b)) { cout<< "Very Good!!\n"<
in your code lines 22-30 there are a few of these

`if(i = 1)`

elsewhere you correctly use == so i presume these are typo's.

in main() you try to pass m,d,s respectively to your subroutines, but these variables do not exist in main() or its parent scope (global), furthermore they aren't used by the routines that you are passing them to, so they are all redundant anyway.

Also, sort out your indentation, well laid out code can make many errors obvious and should be adopted as normal programming practice from day one.

thanks a lot for your contribution jaybob66 , yet i am still confused with the error that comes with the code i just have adjusted .

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106`` ``````#include #include void Multiplication(double a, double b,double &l); void addition(double a, double b,double &m); void division(double a, double b,double &d); void subtraction(double a, double b,double &s); double answer = 0 ; using namespace std; int main() { double a = (rand() % 10) + 1; double b = (rand() % 10) + 1; double i; double l,m,d,s ; cout<<"\n\n This is a Program to teach Elementary Students how to do Mathmatical Operations \n\n"; cout<<"\n\nPress 1 for Multiplication , 2 for addition , 3 for division ,and 4 for subtraction\n\n"; cin>>i; if(i == 1) cout<> answer; if(answer ==(a*b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a+b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a/b)) { cout<< "Very Good!!\n"<> answer; if(answer ==(a-b)) { cout<< "Very Good!!\n"<
i have wrote again your program . check it and if any trouble feel free to ask

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142`` `````` #include //#include #include #include using namespace std; bool ans=false; void add() { float x; float a= rand()%100; float b=rand()%100; cout<< "value of a--------------------"<>x; if(x==(a+b)) { cout<<"\nyour ans true\n"; ans =true; } else { cout<<"\n wrong answer. TRY AGAIN\n"; } } void sub() { float x; float a= rand()%100; float b=rand()%100; cout<< "value of a--------------------"<>x; if(x==(a-b)) { cout<<"\nyour ans true\n"; ans =true; } else { cout<<"\n wrong answer. TRY AGAIN\n"; } } void mul() { float x; float a= rand()%100; float b=rand()%100; cout<< "value of a--------------------"<>x; if(x==(a*b)) { cout<<"\nyour ans true\n"; ans =true; } else { cout<<"\n wrong answer. TRY AGAIN\n"; } } void divide() { float x; float a= rand()%100; float b=rand()%100+1; cout<< "value of a--------------------"<>x; if(x==(a/b)) { cout<<"\nyour ans true\n"; ans =true; } else { cout<<"\n wrong answer. TRY AGAIN\n"; } } int main() { while(1) { cout<<"elementry maths\n"; cout<<"1 add \n"; cout<<"2 sub \n"; cout<<"3 mul \n"; cout<<"4 divide\n"; cout<<"5 exit \n"; cout<<"enter your choice\n "; int choice; cin>>choice; ans=false; while(ans==false) { switch(choice) { case 1:add(); break; case 2:sub(); break; case 3:mul(); break; case 4:divide(); break; case 5: cout<< "EXIT"; exit(0); } } } return 0; } ``````
your == problem also occurs at line 24,26,28

if you have an error message from the compiler always post it with your code so we can see what it is complaining about.
Topic archived. No new replies allowed.