?
Solved

Needs help in logic

Posted on 2011-02-12
3
Medium Priority
?
375 Views
Last Modified: 2012-05-11
Hi guys: Program display each salesperson's commission. The commission is calculated by xplying the sales person's sales by 10%. My code is not working correctly needs help.

#include<iostream>
using namespace std;
int main()
{
      double sales = 0.00;
      double commission = 0.00;
      cout << "Enter a sales amount==>";
      cin >> sales;
      while (sales > 0.0)
       {
            commission = sales * .1;
            cout << commission << endl;
       }

      system("pause");
      return 0;
}
0
Comment
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 2000 total points
ID: 34879125
Replace this

   while (sales > 0.0)

with

   if (sales > 0.0)

0
 

Author Closing Comment

by:mustish1
ID: 34879143
Thanks.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34879153
I'm assuming you put the while loop in there for error checking. This is good and it should be in there. Since this is quite clearly an academic exercise (homework or learning on your own), I won't give direct answers. However, I think you want something like

while (sales < 0)
{
  cout error and ask again;
  get the input again;
}
Now do the calculation outside the loop;
And display it;
 
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question