none
c++ homework RRS feed

  • Question

  • I have to do a program that the user enters the function in the sense that they dicide if it's addition, multiplcation, ect in the function
    Wednesday, February 12, 2014 12:13 AM

Answers

  • Look into switch statements for user input (maybe '1', '2', '3', or '4' or 'a', 's', 'd', or 'm' for the 4 math operations). The rest is just using the operator in their proper case blocks and displaying a result.

    At it's core, it's that simple... With some ambition I'm sure you could write it on your own.

    All else is just for the menu to show the user what they have for choices, and looping to restart the process, among any other extras you may have for such a simple implementation of a calculator for 2 operands.


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum


    Wednesday, February 12, 2014 2:46 AM
  • Just try to write your own then post here if it is not working correctly.  You need to do the following

    1. Prompt to enter the data. For ex two numbers.

    2. Prompt a menu to user to select choice.

    3. After getting choice, invoke function say int Calculate( int choice, int Num1, int Num2 ) 

    4. In calculate you should write as follows

    switch( choice )

    {

    case 1: //addition

    return Num1 + Num2;

    .

    .

    .

    Similarly write code for other calculation also.

    }


    Thanks, Renjith V R

    Thursday, February 13, 2014 6:05 AM

All replies

  • Obviously, the description of what you are supposed to do is probably more complete that what you have posted.

    Be aware that we don't do homework exercises here for you. You have to do the work. If you hit a particular programming  problem, describe it in detail and we will offer you some help.

    Wednesday, February 12, 2014 12:47 AM
  • Look into switch statements for user input (maybe '1', '2', '3', or '4' or 'a', 's', 'd', or 'm' for the 4 math operations). The rest is just using the operator in their proper case blocks and displaying a result.

    At it's core, it's that simple... With some ambition I'm sure you could write it on your own.

    All else is just for the menu to show the user what they have for choices, and looping to restart the process, among any other extras you may have for such a simple implementation of a calculator for 2 operands.


    If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
    Visit the Forum: TechLifeForum


    Wednesday, February 12, 2014 2:46 AM
  • Just try to write your own then post here if it is not working correctly.  You need to do the following

    1. Prompt to enter the data. For ex two numbers.

    2. Prompt a menu to user to select choice.

    3. After getting choice, invoke function say int Calculate( int choice, int Num1, int Num2 ) 

    4. In calculate you should write as follows

    switch( choice )

    {

    case 1: //addition

    return Num1 + Num2;

    .

    .

    .

    Similarly write code for other calculation also.

    }


    Thanks, Renjith V R

    Thursday, February 13, 2014 6:05 AM