| Jacky Billards (5) | |||
|
Hello, I'm trying to do a simple calculator in c++ and slowly expand on it But, at the moment I'm stuck. My code reads:
And it is fine for certain problems. But what if for the cin cin >> x >> u >> y >> u2 >> z;They don't want to fill every space? For example, they only want to input "2 + 2" instead of "2 + 2 + 2" So How would you make a 'cin' that is optional and you can just press the 'enter' instead of having to add "+ 0" at the end of "2 + 2"? | |||
|
|
|||
| SamuelAdams (321) | |||||
|
Hi I have been thinking about this too. I needed a program to add a string of numbers. Since then I have been thinking about how to subtract and multiply, so forth... BTW< yours does not * or / before it + or -'s so the answer is wrong.
The answer should be 4 I will look at this more later, but for now I'll just post my add program. Currently it only adds but, it will add from 2 to millions of numbers as long as they don't total over 2,147,483,647. Maybe you can find something in it to use.
| |||||
|
|
|||||
| Jacky Billards (5) | |
Thank you, I will be able to take a more detailed look at your code after I figure out how to run it. Because on line 63int x = atoi(argv[count]); // convert to int I cannot figure out what you meant "atoi" to be. Seems like a simple syntax error to me | |
|
|
|
| cstarter2000 (90) | |
| Try using a bool type variable. Create an if statement that states that if the bool variable is true, take in 2 numbers. Otherwise, take in three. Try experimenting with that. Also, you should use system("CLS") to clear the screen after every problem. Hope I helped! | |
|
|
|