PROBLEM:
Write a program to calculate the commission based wages of a computer salesman. His basic wage is £50 per week and he is expected to sell at least 10 computers. If he sells more than 10 computers, he receives an extra £5.50 per computer he sells after the 10th computer.
SOLUTION:
The basic algorithm could be drawn as:-
The structure of the program would then be:-
DECLARE CONSTANTS
DECLARE VARIABLES
PROMPT USER TO ENTER NUMBER OF COMPUTERS SOLD
READ IN NUMBER
CALCULATE PAY
IF SELLS MORE THAN 10
CALCULATE COMMISSION
OUTPUT PAYMENT
adding the actual code to the above:-
#include <stdio.h>
#define BASIC_PAY 50
#define LEVEL 10
#define COMMISSION 5.5
main()
{
//DECLARE VARIABLES
float pay, commission_pay;
int num_computers;
//PROMPT USER TO ENTER NUMBER OF COMPUTERS SOLD
printf("Please enter number of computers sold: \n");
//READ IN NUMBER
scanf("%d", &num_computers);
//CALCULATE PAY
if (num_computers > level)
{
commission_pay = (num_computers - LEVEL)* COMMISSION;
pay = BASIC_PAY + commission_pay;
}
else
pay = BASIC_PAY ;
//OUTPUT PAYMENT
printf("Your wage for this week is %d pounds \n", pay );
}
NOTE that this is only one possible solution to the problem.
Try to think of some alternative methods of solving this problem.
Back to Main Page for Lecture 3 |