CS1101C Lab 1 (Odd Week)
Credit Card Points
The deadline for this lab question is Friday 09 February 2007,
23:59:59 hours.
The name of your C program file must be called points1.c,
files with any other name will not be marked.
Preliminary
Credit card companies award points for money spent using their cards.
These points can then be converted to miles which can be used to redeem
free plane tickets on certain airlines.
Earning Points
A particular credit card awards you five points for every
block of eight Singapore dollars (SGD) spent. No points
are given for partial blocks. So, if you spend SGD 16, you will
get ten points. If you spend SGD 23, you will still get
ten points.
Earning Miles
Furthermore, every block of eight points is worth five
miles. Once again, no miles are awarded for partial blocks. So, if you
have 40 points, you will get 25 miles. If you have
45 points, you will still get 25 miles.
Double Rewards
By default, the credit card company always gives you double the
amount of points, called double rewards. So, if you spend SGD
16, instead of getting ten points, you will get 20
points.
Platinum Rewards
But there are certain shops (called platinum shops) which have a
special arrangement with the credit card company. If you spend money at
these platinum shops, you will get platinum rewards, and
instead of getting double points, you will get 10 times
the normal amount of points. So, if you spend SGD 16 at a
platinum shop, instead of getting ten points, you will get
100 points.
Your Task
Write a program called points1.c that prompts the user for the
amount of money spent, as well as the type of spending (ask the user to
key in 1 for double spending, 2 for platinum spending). Your program
will compute and display the number of miles earned.
Template
The following points1.c
program has been provided for you that reads in the two inputs. You must
follow the template given below. Your task is to simply extend the
program to compute and print out the number of miles earned.
/**********************************************************************/
/* Matric Number: U061234A and U069876B */
/* Userid: u0601234 and u0609876 */
/* (For those doing pair programming, only ONE of you should submit */
/* your program. The other student should NOT submit.) */
/* Lab: 1 */
/* Lab Group Number: 99 */
/* Lab TA's Name: Who needs a lab TA when you're Bill Gates? */
/* Lab Session Date: 07 February 2007 */
/* Lab Session Time: 1000 - 1145 */
/* Title: Points to Miles conversion. */
/* Purpose: Perform Points to Miles conversion. */
/**********************************************************************/
#include <stdio.h>
int main(void)
{
/* Variable declaration.
You can declare any other variables here. */
int spending, type;
/* Get user input. */
printf("Enter amount of spending in SGD: ");
scanf("%i", &spending);
printf("Enter type of rewards (1=double, 2=platinum): ");
scanf("%i", &type);
/* Compute and print result here. */
return 0;
}
Sample Runs
Assuming that the executable is points1, a sample run of the
program is shown below. User input is denoted in bold.
$ gcc -Wall points1.c -o points1
$ ./points1
Enter amount of spending in SGD: 123
Enter type of rewards (1=double, 2=platinum): 1
Your spending is: SGD 123
Type of rewards: 1
Number of points earned: 150
Number of miles earned: 90
$ ./points1
Enter amount of spending in SGD: 123
Enter type of rewards (1=double, 2=platinum): 2
Your spending is: SGD 123
Type of rewards: 2
Number of points earned: 750
Number of miles earned: 465
$
Points to Note
- For simplicity, we assume that user input will always be within the
range of permissible values, so there is no need to perform any explicit
checks on the data entered by the user. You may assume that the amount
of spending is always an integer between SGD 0 to SGD 1,000,000,000
inclusive.
- Do not use any other data types except int. That means you
are not allowed to use double, float, char,
etc. You are only allowed to use the int data type and nothing
else.
- The only conversion specifier allowed within printf
statements is strictly %i (or %d).
- Do not use any logical (&&, ||, !) or bit-wise (&, |, ^,
!, <<, >>) operators.
- Do not use any selection statements (if, if-else, switch),
repetition statements (while, do-while, for), nor the conditional
operator "?:".
- Do not use any functions from the math library.
Ponder
70,000 miles is enough for you to redeem a round-trip Economy
Saver class ticket to Paris, the City of Lights. How much spending is
required to earn 70,000 miles, with (a) double rewards, and with
(b) platinum rewards?
This document, index.html, has been accessed 21 times since 25-Jun-24 11:57:13 +08.
This is the 1st time it has been accessed today.
A total of 14 different hosts have accessed this document in the
last 445 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 4 times.
If you're interested, complete statistics for
this document are also available, including breakdowns by top-level
domain, host name, and date.