This is my objective: Develop an adder application in C++ that will either add floating point numbers provided on the command line when the application is run or enter an interactive mode and add floating point numbers provided by the user interactively if no inputs are provided on the command line. Ctrl-Z terminates user input in interactive mode.
When I try to run this and input add
, I will get the else if statement, but when I try to type add 1 2 3
, I will still get the else if statement instead of the if statement.
What do I do so that it recognizes if I input add 1 2 3
it will make use of the if statement?
One more thing, how do I make multiple inputs in 1 line without it having a limit?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string operation;
int num1, num2, num3;
cin >> operation;
if(operation != "add"){
cin >> num1 >> num2 >> num3;
cout << num1+num2+num3;
} else if (operation =="add") {
cout << "Type numbers to be added, 1 per line. Ctrl-Z to end input.";
}
return 0;
}