char choice;
float inputa, inputb;
cin >> inputa >> choice >> inputb;
while(inputa != 0 && choice != '0' && inputb != 0)
{
cout << " = " << calculation(inputa,choice,inputb) << endl << endl;
cin >> inputa >> choice >> inputb;
}
system("PAUSE");
return 0;
This is what the screen looks like:
5 + 4
= 9
The user gives their input and presses enter, so that's what takes them to the next line I guess, but is there a way for it to show:
5 + 4 = 9
After the result is shown, it would use the endl
to go to the next line and the user can input their problem again.
I'm a complete beginner so sorry if the question doesn't make a lot of sense.
You can't use do it since cin
prints every character after you hit it. You will have to define your own input function.
For exemple you can use getch
in the conio.h
(This is not an efficient solution since getch accept only one character. You will have to fin another way. The importent here is to get the idea).
#include <iostream>
#include <conio.h>
using namespace std;
void input(float *a, char *c, float *b)
{
char in;
do {
in = getch();
cout << in;
} while (in == ' ');
*a = in - '0';
do {
in = getch();
cout << in;
} while (in == ' ');
*c = in;
do {
in = getch();
cout << in;
} while (in == ' ');
*b = in - '0';
}
int main()
{
char choice;
float inputa, inputb;
cout << "Expression: ";
input(&inputa, &choice, &inputb);
cout << " = " << inputa+inputb << endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With