Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Scenario 1:

Rent A Van wants a program that ​calculates the total cost of renting a va​n. Customers
pay​ a base fee plus a charge per mile driven​. ​RM700 is the base fee​, and the charge
per mile is based on the table below. Request the ​input from the user​. If ​value entered
is not positive, ask user to re-enter the correct value ​and ​display text message​. You
also need ​to use and apply basic loop structure​.

Mileage Extra Charge

0-99 RM 100

100-500 RM 320

> 500 RM 500

#include<stdio.h>

int main ()
{
int mile;
float bill, fee=700, a=100, b=320, c=500;

printf("Please enter mile travelled : ");


scanf("%d", &mile);

while(mile<0)
{
printf("Please re-enter the value.\n");
main() ;
break;
}

if(mile>0 && mile<=99)


{
bill = fee + a;
printf("Your bill is : RM %.2f", bill );
}

else if(mile >= 100 && mile <=500)


{
bill = fee + b;
printf("Your bill is : RM %.2f", bill );
}

else if(mile > 500)


{
bill = fee + c;
printf("Your bill is : RM %.2f", bill );
}

return 0;

}
Scenario 2:
A student is only qualified for a scholarship if he/she has studied for more than 1 year,
CGPA is not less than 3.0 and guardian’s salary is less than RM1000. Otherwise,
display “You are not qualified for scholarship”.

Show the problem analysis, produce the pseudocode, draw the flowchart and write
the C program.

(Total marks:40)

#include<stdio.h>

int main ()
{
int month;
float CGPA;
int salary;

printf ("Please insert months studied : \n");


scanf ("%d", &month);

printf ("Please insert CGPA: \n");


scanf ("%f", &CGPA);

printf ("Please insert salary: \n");


scanf ("%d", &salary);

{
if (month<12 || CGPA<3.0 || salary>1000)
printf("You're not qualified");
else if (month>12 && CGPA>=3.0 && salary<1000)
printf("You're qualified ");
}

return 0;
}

You might also like