reading more than one char
I've written a claculator program in C++, at the moment it prompts for two numbers (which are read as char's), if they aren't numbers it loops until the user inputs a number. The problem I have now, is that only one character can be inputted at a time. Does anybody know how I can rectify this so the first prompt can take as many char as possible as well as the second prompt taking in more than one char, instead of each prompt only accepting one input? I think it needs an array for each variable but each time I try I get a few errors.
Below is the code I have written so far (minus the case statements that go through the operaters that add, subtract etc.):
Code:
#include <iostream.h>
#include <windows.h>
double add(double num1, double num2)
{
return num1 + num2;
}
double subtract(double num1, double num2)
{
return num1 - num2;
}
double divide(double num1, double num2)
{
return num1 / num2;
}
double multiply(double num1, double num2)
{
return num1 * num2;
}
//Main function
int main()
{
//Variable declarations
char first_input;
char second_input;
double num1;
double num2;
char op;
bool valid;
cout << "*****************************" << endl;
cout << "** calculator **" << endl;
cout << "*****************************" << endl;
//Do-while loop testing user input
do
{
cout << "Please enter a number: ";
cin >> first_input;
valid = true;
valid = (first_input >= '0' && first_input <= '9');
if(valid){
cout << "Correct data!\n";
num1 = atof(&first_input);}
else
cout << "In-correct data\n";
}while(!valid);
//Do-while loop testing user input
do
{
cout << "Please enter a number: ";
cin >> second_input;
valid = true;
valid = (second_input >= '0' && second_input <= '9');
if(valid){
cout << "Correct data!\n";
num2 = atof(&second_input);
}
else
cout << "In-correct data\n";
}while(!valid);
[code][/code]tagged by Salem