How would I make my command line program respond to what a user types in? Im reading C++ for Dummies at the moment, and I was wondering what I would do to make it respond to what a user types in.

Example:

I declare a variable.

I start a new bracket and put something like

cout << "What type of math problem will you be doing?: ";

Then if the person types 'add' the program starts the addition portion to do an addition problem.

Then I would want it to ask for what the next problem would be.

If the user types done, I would want them to go back to the start portion of the program.

The program should look something like this.

Welcome to MathMan!
---------------------
Enter the type of equation:add
---------------------
You have chosen to add.
Enter X:2
Enter Y:2
The answer to the addition sentence is 4.
Continue?:yes
Enter X:2
Enter Y:5
The answer to the addition sentence is 7.
Continue?:no
----------------------
Welcome to MathMan!
----------------------
Enter the type of equation:done
Press any key to continue...

[Then the program closes]

Yes, I know that this is newbish but I want to know how to do it. A hint would be fine. You don't have to give me the entire answer to my question. I just need atleast a hint? Im new to C++. lol

I just need atleast a hint?

start here

#include <iostring>
using std::cout;

int main()
{
    cout << "What type of math problem will you be doing?: ";
   // put your code here


  return 0;
}

lol Im passed that already. I declared my variables in header files that I coded. Im looking for atleast a hint on how to get the program to respond to user input so that I can execute the action from a declared variable.

you need to post your program. use getline() to get a string that includes spaces.

lol Im passed that already. I declared my variables in header files that I coded. Im looking for atleast a hint on how to get the program to respond to user input so that I can execute the action from a declared variable.

This is what if statements are for.

if (x == "add") {
    add_routine();
}
else if (x == "sub") {
    subtraction_routine();
}
.
.
.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.