Thread: help me with this simple script!

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    help me with this simple script!

    Ok, this is a class project and my tutor helped me get this far however I'm stumped on how to finish, suggestions? I'm VERY new to C++!

    #include <iostream>

    using namespace std;
    int evenorodd(char);


    int main() // main
    {

    char dum; // This character is going to be sent to another function
    // which will determain if it's odd or even
    int OneOrTwo; //will either be 1 or 2, 1 if character is even, 2 if charcter is
    //odd

    cout << "Please enter a number between 0 and 9: ";
    cin >> dum;
    OneOrTwo = evenorodd(dum);

    //if OneOrTwo is 1 then character was even
    //if OneOrTwo is 2 then character was odd


    return 0;

    }

    //what the function does
    int evenorodd(char dum1)
    {
    //if char mod 2 = 0 then number is even so we return 1
    if ((dum1 % 2) == 0)
    {
    return 1;
    }
    //if char mod 2 = 1 then number is odd so we return 2
    else if ((dum1 % 2) == 1)
    {
    return 2;
    }



    }

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    Yes no problem.... pretty much everything is done, all you need is another "if" statement that determines and checks the value of the RETURN statement that was returned from the function and after couple of "cout" 's and you're done....

    for example

    Code:
    OneOrTwo = evenorodd(dum);  // our function returns here  and
                                                      // assigns a return value to OneorTwo
    
    if(OneOrTwo == 1)
      cout << "The character is even!!! \n";
    
    if(OneOrTwo == 2)
       cout << "The character is odd!!! \n";
    
    return 0;
    
    // the end...
    Like I said you tutor helped you litterally to the end and he even put info down for you that should be followed to finish a program.
    To be honest with you, this program doesn't involve much programming knowledge nor C++ for that matter, all it pretty much needs is some logical thinking......practice practice practice...

    ADVICE: for the future try to approach every programming problem as a real life problem, and solve it on paper in plain English as you would be asked to give a verbal solution to a "human - real life" problem and then approach your computer and start programming...

    Good Luck...

    Regards,
    matheo917

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    5
    Hey the program works now, thanks for the advice! Next time I'll try to analyze it a little more from my perspective, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [PAID] Very simple C script - Not working?
    By spadez in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-12-2009, 08:00 AM
  2. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  3. Linux script
    By deltabird in forum Linux Programming
    Replies: 1
    Last Post: 05-02-2003, 03:31 PM
  4. Language Script..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-30-2003, 06:48 AM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM