Newbie help

This is a discussion on Newbie help within the C++ Programming forums, part of the General Programming Boards category; Hey All, I recently started Learning c++. I have purchased Jumping into c++ (and c++ for Dummies)and have a couple ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    3

    Newbie help

    Hey All,

    I recently started Learning c++. I have purchased Jumping into c++ (and c++ for Dummies)and have a couple of Questions.

    1. Are there answers for the Practice Problems anywhere from Jumping into C++

    2. Also Having an issue with one of the Problems: The program runs but doesn't give me the result. Any thoughts?

    Code:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    
    
    using namespace std;
    
    
    int Addition(int Num1, int Num2)
    {
        int Ans = Num1 + Num2;
        return Ans;
    }
    
    
    int Subtraction(int Num1, int Num2)
    {
        int Ans = Num1 - Num2;
        return Ans;
    }
    
    
    int Multiplication(int Num1, int Num2)
    {
        int Ans = Num1 * Num2;
        return Ans;
    }
    
    
    int Division(int Num1, int Num2)
    {
        int Ans = Num1 / Num2;
        return Ans;
    }
    
    
    int main()
    {
         int nAns; //For Loop Version of Program
         int nNum1;
         int nNum2;
         char cOperand;
    
    
    
    
         cout << "Please enter the First Number: ";
         cin >> nNum1;
         cout << "\nPlease enter the Second Number: ";
         cin >> nNum2;
         cout << "\nPlease enter your Operator as + - /  * %: ";
         cin >> cOperand;
         //cout << "The Answer is: " << ans << "\n";
    
    
         switch (cOperand)
         {
             case '+':
             nAns = Addition(nNum1, nNum2);
             return nAns;
             break;
    
    
             case '-':
             nAns = Subtraction(nNum1, nNum2);
             return nAns;
             break;
    
    
             case '*':
             case 'x':
             case 'X':
             nAns = Multiplication(nNum1, nNum2);
             return nAns;
             break;
    
    
             case '/':
             nAns = Division(nNum1, nNum2);
             return nAns;
             break;
    
    
             default:
             cout << "Invalid Operator!";
             break;
    
         }
         cin.ignore();
         cout << "The Answer is: " << nAns;
    
    }
    Thanks for any help

    Edit: It actually looks to be getting the correct answer as when I run the program in Code:Blocks it exits and says: Process returned 10 (0xA). Its just not giving me the output of the answer.
    Last edited by Madord; 04-26-2012 at 03:07 AM.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    remove all the
    Code:
        return nAns;
    from your switch cases.
    returning from main will terminate the program and your output statements will never be reached.
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    3
    Quote Originally Posted by ZuK View Post
    remove all the
    Code:
        return nAns;
    from your switch cases.
    returning from main will terminate the program and your output statements will never be reached.
    Kurt

    OMG. Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another newbie asking for help!
    By ericdabear in forum C Programming
    Replies: 9
    Last Post: 03-15-2010, 10:09 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. SDL + Newbie
    By Livijn in forum Game Programming
    Replies: 7
    Last Post: 04-30-2007, 11:20 PM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 11:27 AM
  5. Newbie help
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2002, 03:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21