Solved

Needs help in logic

Posted on 2011-02-12
3
374 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

695 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