Workshop 2
Workshop 2
Workshop 2
In this workshop, you will code and execute a C-language program that accepts
numerical values from the user, stores the values in variables of appropriate data
type, performs calculations on the stored variables and casts from one data type
to another.
LEARNING OUTCOMES
Upon successful completion of this workshop, you will have demonstrated the
abilities:
SUBMISSION POLICY
All your work (all the files you create or modify) must contain your name,
Seneca email and student number.
In the Visual Studio solution explorer panel, open and write your code in cashRegister.c for
workshop 2.
Start the program by asking the user to enter the amount due. Print the following message:
Assume the user enters 8.68, this is what the screen should look like:
(<ENTER> means hitting the enter key)
Calculate the number of loonies and quarters required to pay the amount due and display the
following:
PART 1 SUBMISSION:
To test and demonstrate execution of your program use the same data as the output example
above.
If not on matrix already, upload your cashRegister.c to your matrix account. Compile and
run your code and make sure everything works properly.
PART 2: (30%)
After completing part 1, edit and upgrade cashRegister.c to add the GST to the total entered by
the user.
Display the amount of the GST and then the total due. Then display the number of quarters,
dimes, nickels and pennies required to pay the total amount.
Problem: 8.68 * .13 is equal to 1.1284, which should be rounded up to 1.13, and the format
specifier %.2lf will display as 1.13, but the number will be truncated to 1.12 on a C standard
compiler, such as matrix, if we multiply by 100 and cast to an int, which we must do at some
point in the program.
GST = amountOwing * .13 + .005; (result is 1.1334 which will resolve to 1.13 when either
rounded or truncated)
After Calculating the number of loonies required, subtract the number of loonies from the
amountOwing, then cast the remaining decimal portion to an int. The subsequent operations
must be done using integer division and modulus. Although the answer can be derived without
using the modulus operator, failure to use modulus will result in a grade of 0 for the At_Home
portion of the workshop.
Hints:
- Read about casting, division and modulus in the notes
- 0.35 * 100 = 35
- You can output the value 5, stored in an int variable as $0.05 like this:
printf(“$%1.2f”, (float)intBalance/100);
PART 2 SUBMISSION:
To test and demonstrate execution of your program using the same data as the output example
above.
If not on matrix already, upload your cashRegister.c and reflect.txt to your matrix
account. Compile and run your code and make sure everything works properly.
Then run the following script from your account: (replace profname.proflastname with your
professors Seneca userid and replace NAA with your section)
~profname.proflastname/submit 144w2/NAA_home <ENTER>