### FUNCTIONS HELP!!!

hi. i wrote a function and i am supposed to write the same function into it and i keep getting errors. how would i write the same function into the first function. the only thing different would be the parameters. thanks
this is what i have:
 ``123456789101112131415161718192021`` ``````int didtheproducthit (int x, int y) { if (lucky==x*y) //error says expected expression cout<< x << " and " << y << " multiply to 6" << endl; else cout<< x << " and "<< y << " do not multiply to 6" << endl; return lucky; int didtheproducthit (int y, int z) { if (lucky==y*z) cout<< y << " and " << z << " multiply to 6" << endl; else cout<< y << " and "<< z << " do not multiply to 6" << endl; return lucky; int didtheproducthit (int x, int z) { if (lucky==x*z) cout<< x << " and " << z << " multiply to 6" << endl; else cout<< x << " and "<< z << " do not multiply to 6" << endl; return lucky; }};}``````
Last edited on
thats nested functions which u cant do in c++ i would take a look at c++ functions tutorial
thanks. i did look at the functions tutorial but they dont explain how i can use the a function inside the same function.
What do you mean by 'use'? You mean call? That's a different syntax than what you're doing (a definition). And what is the difference between all those functions...? They all do the same thing.
the only difference between these functions are the parameters. i am supposed to call it three times but im not sure how to do it. is there a way that the main function can call it three times. this is my whole program so far:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869`` ``````#include using namespace std; const int lucky=6; void introduction (); int findouthowmany (int x, int y, int z); int didtheproducthit (int x, int y); int main() { int x, y, z; introduction (); cout<< "the three original integers are "<< endl; cin>>x; cin>>y; cin>>z; cout<< findouthowmany << " numbers are equal to the lucky number 6" << endl; didtheproducthit (x,y); return 0; } void introduction() { cout<< " This program will end when there are at least eight sets of data values."<< endl << endl; return; } //findouthowmany will determine how many of the three integers: int x, y, and z are equal to the lucky number. it will print how many of the three numbers are equal. int findouthowmany (int x, int y, int z) { int count=0; if (lucky==x) count++; if (lucky==y) count++; if (lucky==z) count++; return count; } //didtheproducthit will determine whether or not the product of parameter x and y values equal the lucky number and it will print a comment saying whether or not they multiply to 6. this function will repeat three times in the main function. int didtheproducthit (int x, int y) { if (lucky==x*y) cout<< x << " and " << y << " multiply to 6" << endl; else cout<< x << " and "<< y << " do not multiply to 6" << endl; return lucky; int didtheproducthit (int y, int z) { if (lucky==y*z) cout<< y << " and " << z << " multiply to 6" << endl; else cout<< y << " and "<< z << " do not multiply to 6" << endl; return lucky; int didtheproducthit (int x, int z) { if (lucky==x*z) cout<< x << " and " << z << " multiply to 6" << endl; else cout<< x << " and "<< z << " do not multiply to 6" << endl; return lucky; };};}``````
Last edited on
no you are obviously not looking at c++ functions start over with a tutorial for framework
Topic archived. No new replies allowed.