+ 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

28th Jun 2019, 8:29 AM
Foxie
Foxie - avatar
7 odpowiedzi
+ 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
28th Jun 2019, 12:37 PM
Agent_I
Agent_I - avatar
+ 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
28th Jun 2019, 8:48 AM
Agent_I
Agent_I - avatar
+ 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 ?
28th Jun 2019, 8:55 AM
Foxie
Foxie - avatar
+ 2
Shreyas Domde Can you show me the code after you changed it?
28th Jun 2019, 9:04 AM
Agent_I
Agent_I - avatar
+ 1
Now its saying "illegal instruction " 😭😭
28th Jun 2019, 12:21 PM
Foxie
Foxie - avatar
+ 1
Thanks !! It worked !!!
28th Jun 2019, 2:12 PM
Foxie
Foxie - avatar