+ 2
How can I use this function in case 1 ?
#include<iostream> #include<ctime> #include<stdio.h> #include<math.h> #include<conio.h> using namespace std; int easy(int a , int b , int z[2]) { a = (rand()%100); b = (rand()%100); cout<<a<<"+"<<b; cin>>z[0]; z[1]=a + b ; if(z[1]==z[0]) { cout<<"YOU ARE CORRECT !!"; } else { cout<<"Sorry you are incorrect , try again "; }int main() { int i,m; do { cout<<"Select the level : \n1.Easy\n2.Med\n3.Hard\n4.Insane\n"; cin>>i; switch(i) { case 1 : { } } } I want to use that 'easy' function in case 1 , how can I do that ? Thanks for helping
7 Answers
+ 2
Shreyas Domde
Your function declaration, all of your function (easy, med, hard, and ins) have an int as its return value, you don't need any return value so you have to change it to void. Therefore, you should write down void easy() instead of int easy() and so on. Don't change the main function and make sure you put return 0 in the end of the main function
+ 2
switch(i) {
case 1:
easy();
break;
}
I think you should also change the easy function to easy() without any argument and declare the variables inside the function since judging by your code, it doesn't need any argument
+ 2
If I deleted the parameter and shift the int in the function , it becomes an error and so I can't run that 'easy' function.
Any other idea ?
+ 2
Shreyas Domde
Can you show me the code after you changed it?
+ 1
Now its saying "illegal instruction " đđ
+ 1
Thanks !! It worked !!!