Solved

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

Posted on 2004-04-03
1
149 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
1 Comment
 
LVL 10

Accepted Solution

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

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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…
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now