Solved

Needs help in logic

Posted on 2011-02-12
3
370 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
3 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 83
word0 challenge 3 78
Permutation and Combination 9 72
Modify a small python script 19 97
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now