Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

modifying a program so it uses a program defined function to get and validate sales.

Posted on 2004-04-03
1
Medium Priority
?
158 Views
Last Modified: 2010-04-01
I need to modify this program so that it uses a value-returning function to get and validate the sales amount entered by the user. The function should return a value such as Y or N that indicates if the sales amount is valid.  The return value should determine whether to calculate and display the commission.  My problem is when I enter a negative number as the sales it returns a negative commission instead of the "No commission calculated" message.

//T9AppE10.cpp - displays the commission

#include <iostream>
using namespace std;

//function prototype
float calcCommission(int);
int getAndValidateSales(int);

int main()
{
      int sales        = 0;
      float commission = 0.0;
      int salesData = 0;
      
      //enter input data
      cout << "Enter sales: ";
      cin >> sales;


      //validate input data
      if (salesData = 1)
      {
            //calculate and display commission
            commission = calcCommission(sales);
            cout << "Commission: " << commission << endl;
      }
      else
            cout << "No commission calculated" << endl;
      //end if

      return 0;
}   //end of main function

//*****program-defined functions*****
float calcCommission(int amountSold)
{
      //calculates and returns the commission
      float commDollars = 0.0;

      if (amountSold <= 100000)
            commDollars = amountSold * .02;
      else if (amountSold <= 400000)
            commDollars = 2000 + .05 * (amountSold - 100000);
      else commDollars = 17000 + .1 * (amountSold - 400000);
      //end ifs
      return commDollars;
}      //end of calcCommission function

int getAndValidateSales(int &sales)
{
      int salesData = 0;

      if (sales > 0)
            salesData = 1;
      else salesData = 2;
      return salesData;
}      //end getAndValidateSales
0
Comment
Question by:SinSual
[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
1 Comment
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 2000 total points
ID: 10748705
You have not called getAndValidateSales () fuction
call that function after accepting the value of sales and take the return value in salesData

something like

salesData = getAndValidateSales ( sales ) ;
if ( salesData == 1 ) .............

Also, in your if condition, u are assigning 1 to salesData instead of checking it
In C/C++, for checking equality, u should use == as shown above

Amit
0

Featured Post

Technology Partners: 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Suggested Courses

610 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