Using function integer arguments with my C++ program -
i have little project do, i've created program when user types number, if it's or odd. used function. here's question:
how use integer arguments in function program? (my program does work, doesn't use integer arguments.)
instructions
write c++ function accepts integer argument, determines whether passed integer or odd, , displays result of determination. (hint: use % operator.)
make sure function called main(). test function passing various data it.
my code
#include <iostream> using namespace std; void oddeven() //my function { int num; cout << "please enter number " << endl; cin >> num; if (num % 2) { cout << "it's odd" << endl; } else { cout << "it's even" << endl; } } int main() //main program { oddeven(); //calling function return 0; }
sample program:
#include <iostream> using namespace std; void oddeven(int num/*num integer argument*/){ if (num % 2) { cout<<"it's odd"<<endl; } else { cout<<"it's even"<<endl; } } int main() //main program { int x; cout<<"please enter number "<<endl; cin>>x; oddeven(x); //calling function return 0; }
Comments
Post a Comment