Hi! In this program, I am using switch statements in order to execute commands from a made up language. However, I cannot seem to get my program to distinguish DOUBLE from DIV, as you can only use one character to discriminate between cases. I would like to use an If or If/else statement to distinguish DOUBLE from DIV. I cannot use "Hello[1]" or however you would put it. Would I make an empty variable? What goes in the if ( ) ? Help? Thanks so much!
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
usingnamespace std;
int main()
{
char userInput;
int userAdd, userAdd1, userAnswer;
string userCON1, userCON2;
cout << "Please enter the operation: \n";
cin >> userInput;
switch (userInput)
{
case'A' :
cout << "You are using the ADD function.\n";
cin.ignore(200, '\n');
cout << "Please enter an integer.\n";
cin >> userAdd;
cout << "Thanks. Please enter the second integer.\n";
cin >> userAdd1;
userAnswer = userAdd + userAdd1;
cout << "The answer is: " << userAnswer;
break;
case'C' :
cout << "You are using the COMBINE function.\n";
cin.ignore(200, '\n');
cout << "Please enter a string.\n";
getline(cin, userCON1);
cout << userCON1;
break;
case'D' :
///?
if ( )
cout >> "You are using the DOUBLE function";
else
cout >> "You are using the DIV function";
//?
}
return 0;
That is correct. I cannot use that specifically, but I can put switches in switches or ifs in switches. I just am a little stuck on this part. Thank you for the help thus far. Do you know if there is a way to do that?
I think that both pieces of advice are very helpful, but I cannot change the format of the current code that I am providing. I must do this inside of a switch statement and preferably with an embedded 'if' statement. Thank you for the advice, though. I will save it for later purposes.
cout << "Please enter the operation: \n";
cin >> userInput;
switch (userInput)
{
case'A' :
cout << "You are using the ADD function.\n";
cin.ignore(200, '\n');
cout << "Please enter an integer.\n";
cin >> userAdd;
cout << "Thanks. Please enter the second integer.\n";
cin >> userAdd1;
userAnswer = userAdd + userAdd1;
cout << "The answer is: " << userAnswer;
break;
case'C' :
cout << "You are using the COMBINE function.\n";
cin.ignore(200, '\n');
cout << "Please enter a string.\n";
getline(cin, userCON1);
cout << userCON1;
break;
case'D' :
cin >> userInput; // Get another letter
///?
if ( userInput == 'O' )
cout >> "You are using the DOUBLE function";
else
cout >> "You are using the DIV function";
//?
If this were a course in teaching people to run marathons, the initial objective seems to be to create a level playing field by breaking the legs of all the students.
Then teaching them how to crawl, hobble, walk and finally run at some reduced speed.