So I am having trouble with this program it works but I need to input 2 values from the same line separated by a space using cin double chevrons!? I cannot use stringstream have to use some form of a char* token[] function using atof without having the program skip the second input if a non numeric is entered such as ten instead of 10, also need to have input read as a floating point or double int?! please correct or help me this is the code I have
There are several ways to tackle this. One is to get the entire line as a single character string, and then parse it to get the two numbers. Another would be to get the two parts as two separate strings, as here:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setprecision;
#include <cstdlib>
int main()
{
// Declare variables for cost, pay and change as well as double int
// for declaring change total with decimal point
double pur = 0;
double tend = 0;
char cpur[50];
char ctend[50];
// Ask the user to input both purchase and tendered amount
cout << "Please enter the Purchase amount and amount tendered(separated by a space): \n";
cin >> cpur >> ctend;
pur = atof(cpur);
tend = atof(ctend);
// display the input as a string, them as a number
cout << "cpur = " << cpur << endl;
cout << "ctend = " << ctend << endl;
cout << "\n---------------------\n\n";
cout << "pur = " << pur << endl;
cout << "tend = " << tend << endl;
return 0;
}
ya I used that but he said he wanted the double chevron usage in this program very anal and not letting me get credit till I do it the "way" he taught in class but thanks Ill try and that