why is it showing output like this ?

so im trying to write code for this.
One large chemical company pays its salespeople on a commision basis.The sales people receive $200 per week plus 9 percent of their gross sales for the week ( found on net)

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main()
{
string mystr;
float salary;
float sales;
cout<< "enter no of" << sales <<endl ;
getline (cin, mystr);
stringstream(mystr) >> sales;
salary=(0.09*sales)+200;
cout<<"total sal:" << salary <<endl;
return 0;
}

wrote that but when ever im compiling its showing enter no 5.04467e-044 instead of sales ?

http://i552.photobucket.com/albums/jj339/Kingofgames123/Untitled1.png
I'd recommend using the 'double' type for your floating point variables, and initializing them before use. You didn't specify a value for the 'sales' variable before using it, so the program just displayed the "garbage" from the last time it was used. Try doing something like this.

1
2
double salary = 0;
double sales = 0;


It would also be so much easier to just do this to get the value of 'sales' instead of saving it into a string, and then putting the string into the 'sales' variable. You don't have to include the 'sstream' file, or the 'string' file this way, too!

1
2
cout << "enter no of sales" << endl;
cin >> sales;
Last edited on
thx its working now. :)
Topic archived. No new replies allowed.