Share
Explore BrainMass

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

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;
}

Attachments

Solution Summary

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

$2.19