I have to a small assignment, and I am stoked on the last part. I basiclly have
to find 9 percent of any number entered by the user and then add 200 to it.
I will not post the assignment code cause its huge but I have created a small
dummy program to see if I can get the calculation correct. I have never been good at percentage calculations lol.
This is my best effort, it compiles but its the wrong output. What changes do I have to do to make the output correct?
EDIT: Read the comment above the static_cast for an idea.
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
using std::fixed;
#include <iomanip>
using std::setprecision;
// main function - driver
int main ( void )
{
double sales; // total sales made for the week
double salary; // salary for each employee
cout << "Enter sales in pounds ( enter -1 to quit ): ";
cin >> sales;
while ( sales != -1 )
{
// calculate salary- each employee
// gets 200 standard and 9% of sales
salary = static_cast < double > ( sales ) / 0.9 + 200;
cout << "\nSalary is: " << setprecision( 2 ) << fixed << salary;
cout << "\n\nEnter sales in pounds ( enter -1 to quit ): ";
cin >> sales;
}
cin.get(); // freeze console output window
return 0; // indicate program ended sucsesfuly
}