Explore BrainMass

Explore BrainMass

    Write a program that asks the user for two integers and a character, 'A', 'S', or 'M'.

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a program that asks the user for two integers and a character, 'A', 'S', or 'M'. Call one of three functions that adds, substracts, or multiplies the user's integers, based on the character input.

    This is what I have so far but I cant figure out how to link the character data A, M, or S to the specific funtions.

    #include<iostream>

    using namespace std;

    void main()
    {
    int a, b;
    char c;
    int result=0;

    cout << " Please enter first integer: ";
    cin>> a;

    cout << " Please enter second integer: ";
    cin>> b;

    cout << "nnn(A) Additionnnn(M) Multiplicationnnn(S) SubstractionnnnPlease enter a character input: ";
    cin>> c;
    while (c!='A' && c!='a' && c!='M' && c!='m' && c!='S' && c!='s')
    {
    cout<<"Invalid selection.nnYou must enter a valid selection A, M, or S.nn"<<endl;

    cout<<"Please enter a character input: ";
    cin>>c;
    cout<<endl;
    }//end while
    if (c == 'A' || c == 'a')
    {

    }
    }
    int resultAdd(int num1, int num2)
    {
    int result;
    result = num1 + num2;
    cout<<"The sum of two integers is: " <<result<<endl;
    return result;
    }

    int resultMult(int num1, int num2)
    {
    int result;
    result = num1 * num2;
    cout<<"The multiplication of two integers is: " <<result<<endl;
    return result;
    }

    int resultSub(int num1, int num2)
    {
    int result;
    result = num1 - num2;
    cout<<"The difference between two integers is: " <<result<<endl;
    return result;
    }

    © BrainMass Inc. brainmass.com March 4, 2021, 6:20 pm ad1c9bdddf
    https://brainmass.com/computer-science/cpp/program-asks-user-two-integers-character-40900

    Attachments

    Solution Summary

    Write a program that asks the user for two integers and a character, 'A', 'S', or 'M'.

    $2.49

    ADVERTISEMENT