In this program we will be calculating the salary and the commission of a salesman. He gets paid 10$ an hour plus commission based on the number of widgets sold. The first 50 widgets he doesn't receive any money, for the next 50 widgets (51-100) he makes 1$ commission. for 101-300 he makes 2$ and for 300+ he makes 5$ per. The output should look like this (hours * 10 + 50*0 + 50*1 +200*2 + 100*5) but I don't know how to get that. Thank you for any inputs
#include <iostream>
#include <string>
using namespace std;
bool error(const string & msg);
int main() {
double hours;
double widgets;
cout << "How many hours did you work this month and how many widgets did you sell? " << endl;
cin >> hours >> widgets;
if (!cin) error("Your input is invalid");
if (hours < 0) error("Your input can't be negative");
if (widgets < 0) error("Your input can't be negative");
hours = (hours * 10.00); // Salesman gets paid 10$ an hour
if (widgets = 50) cout << 0; // Salesman doesn't get paid for less than 50 widgets sold
if (widgets > 50 || widgets < 101) cout << widgets * 1.00; // 51-100 Widets sold = 1$ per
if (widgets > 100 || widgets < 301) cout << widgets * 2.00; // 101-300 sold = 2$ per
if (widgets > 300) cout << widgets * 5.00; // anything above 300 = 5$ per
/* my cout should look something like
hours * 10 + 50*0 + 50*1 +200*2 + 100*5
*/
cout << hours + widgets;
}
bool error(const string & msg) {
cout << "Error: " << msg << endl;
exit(EXIT_FAILURE);
}
Aucun commentaire:
Enregistrer un commentaire