This is my program and what it is to do:
QUOTE
Write a program that asks the user to enter a single real (float) number (positive or negative) and outputs twice the number the user entered.
The program must validate the input of the number by first storing it into a character string and then verifying that it only contains digits, decimal point, and negative sign.
Limit the size of the array to 30 characters.
Verify that the maximum number of decimal points in the string is one (1).
Verify that the negative sign (if any) can only be at the first position of the string.
If any of the validation conditions fail, notify the user and request the number again until it is correct.
Once the string is validated, convert the string to float and output the number multiplied by two.
There is no requirement for this program to contain additional functions (other than main) or to request the user if he/she would want to enter a number again after validated.
This is what i have so far, am i off to a good start and what advise or help could you give me.
CODE
#include <iostream>
using namespace std;
int main()
{
char s0;
char s1[30];
cout << "Enter a number: ";
s0 = cin.get();
cin.get(s1,30);
cout << s0 << "\n";
cout << s1 << "\n\n";
char s2[30];
char s3[30];
char s4[30];
cout << "Enter a number: ";
cin.getline(s2,30,' ');
cin.getline(s3,30,' ');
cin.getline(s4,30,' ');
cout << s2 << s3 << s4 << "\n\n";
char s5[30];
char s6[30];
char s7[30];
cout << "Enter a number: ";
cin.get(s5,30,' ');
cin.get(s6,30,' ');
cin.get(s7,30,' ');
cout << s5 << s6 << s7 << "\n\n";
return 0;
}