Using a long double, it seems to cut out a decimal when it increases another digit. The first scan won't work properly, as it only shows 3 decimals, but should have 4, which doesn't concern me, but i'd like it to always have three.
Price: 5.99
Scanned Price (Over and Over) : 000J90120071000002291
Of course it will have to work with different Numbers.
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
long double t, p;
string number21;
cout << "Please enter the price.";
cout << endl;
cin>>p;
t = 0;
cout << "Please scan the the weight.";
cout << endl;
cout << "Scan 1";
cout << endl;
cin >> number21;
string number7 = number21.substr (14);
long double w = atoi (number7.c_str ());
t = w * p * 0.01 + t;
cout <<"Total: $"<<t;
cout << endl;
cout << endl;
int i = 1; while (i++ < 1000)
{
cout << "Scan " <<i;
cout << endl;
cin >> number21;
string number7 = number21.substr (14);
long double w = atoi (number7.c_str ());
t = w * p * 0.01 + t;
cout <<" Total: $"<<t;
cout << endl;
cout << endl;
};
cin.get();
cin.get();
}