A community for students.
Here's the question you clicked on:
 0 viewing

This Question is Closed

uhcoog1989
 3 years ago
Best ResponseYou've already chosen the best response.0here is the question Your program will continue asking for the sales until the user types a negative number for sales, then the program should ask the user, if he/she wants to terminate the program. The program terminates if the user answers yes or y.

Narsat
 3 years ago
Best ResponseYou've already chosen the best response.1I'm not quite sure on C++ syntax, but you need a loop that looks like this: int number; do{ ask value of number from input }while (number >= 0); //This loop will repeat until number is 1 or smaller As for the second part, what happens if the user doesn't want to terminate the program, it starts over?

uhcoog1989
 3 years ago
Best ResponseYou've already chosen the best response.0this is what i have so far it runs just cant get it to ask for termination #include <iostream> #include <iomanip> using namespace std; double CalcCommision (double &sale) { double commission; if(sale <=999) commission= sale * .035; //This equation calculate commission that is 3.5% of sales between $0 and $999 else if(sale >= 1000 <=1999) commission= sale * .040; //This equation calculates commission that is 4% of sales between $1000 and $1999 else if(sale >= 2000 <=2999) commission= sale * .045; //This equation calculates commission that is 4.5% of sales between $2000 and $2999 else if (sale <=3000) commission= sale * .050; //This equation calculates commission that is 5% of sales $3000 or greater return commission; } int main() { string yes; double sale; sale = 0; // initialize sale cout << "5000" <<endl << ".050" <<endl << endl << "In order to exit the program, you must enter a negative number." << endl; cout << "2999: $ "; cin >> sale; while (true) //the while statement starts loop, while statement is being utilized if a positive number is entered //once an ammount is entered, the commission value returned to main module is displayed with CalcCommission {if(sale>=0) {cout << endl; cout << endl; cout << endl; cout << endl; cout << "1000: $" << sale << ".040: $" << CalcCommision (sale) << endl; } else // if a negative number is entered, program jumps here to ask user if they would like to terminate the program { cout << endl; cout << endl; cout<< endl; cout << "y"; cin>>yes; if(yes.compare("yes")==0 } cout << "1999: $ "; cin >> sale; } }

Narsat
 3 years ago
Best ResponseYou've already chosen the best response.1There's two ways to solve this. 1. You can put everything in your main() function inside a big dowhile, with the "yes/y" condition at the end, where you exit the cycle if the user has typed yes or y. 2. Inside an if{ } you can use exit(0), where 0 indicates the status in which the process terminates (0 = normally, no errors). This will end your program. http://www.cplusplus.com/reference/clibrary/cstdlib/exit/
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.