mercredi 22 avril 2015

Using function integer arguments with my C++ program

I have a little project to do, I've created a program that when the user types a number, it will say if it's even or odd. I even used a function. Here's my question:

How do I use integer arguments in a function for the program? (My program does work, it just doesn't use integer arguments.)


Write a C++ function that accepts an integer argument, determines whether the passed integer is even or odd, and displays the result of this determination. (Hint: Use the % operator.)

Make sure your function is called from main(). Test the function by passing various data to it.

My code

#include <iostream>

using namespace std;

void oddEven() //My Function


int num;

cout<<"Please enter a number "<<endl;

if (num % 2)

    cout<<"It's odd"<<endl;
    cout<<"It's even"<<endl;

int main() //Main program


oddEven(); //Calling my Function
    return 0;

Aucun commentaire:

Enregistrer un commentaire