0% found this document useful (0 votes)
20 views7 pages

W2 Lab Exercises

This document contains 4 coding exercises that demonstrate collecting user input and performing basic calculations. Exercise 1 collects biographical data from the user like name, gender, age etc and displays it. Exercise 2 defines rental prices for different car models and displays a table of options. Exercise 3 collects item quantities from a grocery store, calculates prices and displays a receipt. Exercise 4 similarly collects order details for bakery items, calculates totals and displays an invoice.

Uploaded by

rohaida idayu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

W2 Lab Exercises

This document contains 4 coding exercises that demonstrate collecting user input and performing basic calculations. Exercise 1 collects biographical data from the user like name, gender, age etc and displays it. Exercise 2 defines rental prices for different car models and displays a table of options. Exercise 3 collects item quantities from a grocery store, calculates prices and displays a receipt. Exercise 4 similarly collects order details for bakery items, calculates totals and displays an invoice.

Uploaded by

rohaida idayu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

WEEK 2 EXERCISES

EXERCISE 1

#include <stdio.h>

int main()

//declare variable

char name[100];

char gender[10];

int age;

float height;

float weight;

//get input

printf("enter name: ");

scanf("%s", &name);

//get input

printf("enter gender: ");

scanf("%s", &gender);

//get input

printf("enter age: ");

scanf("%d", &age);

//get input

printf("enter height: ");

scanf("%f", &height);

//get input

printf("enter weight: ");

scanf("%f", &weight);

printf("\n \tMY BIODATA\n");


//display data

printf("name: %s\n", name);

//display data

printf("gender: %s\n", gender);

//display data

printf("age: %d\n", age);

//display data

printf("height: %.2fkg\n", height);

//display data

printf("weight: %.2fm\n", weight);

}
EXERCISE 2

#include <stdio.h>

#define SAGA 120.00

#define PESONA 140.00

#define EXORA 200.00

#define MYVI 100.00

#define ARUZ 200.00

int main()

const int insurance = 10;

printf("PULAU CAR RENTAL\n");

printf("'-----------------------------------------'\n");

printf("|VEHICLE MODEL |\tRENTAL PER DAY (RM)|\n");

printf("'-----------------------------------------'\n");

printf("|[1]PROTON SAGA |\t%.2f\t |\n", SAGA);

printf("|[2]PROTON PESONA |\t%.2f\t |\n", PESONA);

printf("|[3]PROTON EXORA |\t%.2f\t |\n", EXORA);

printf("|[4]PERODUA MYVI |\t%.2f\t |\n", MYVI);

printf("|[5]PERODUA ARUZ |\t%.2f\t |\n", ARUZ);

printf("'-----------------------------------------'\n ");

printf("Listed cost excludes car insurance i.e \t%d%%", insurance);

return 0;

}
EXERCISE 3

#include <stdio.h>

int main()

int Qsusu, Qkicap, Qtepung, Qgula, Qsardin;

float susu=3.50, kicap=4.00, tepung=4.00, gula=5.40, sardin=3.70, total;

printf("Enter the quantity of Susu Sihat Pekat Manis :");

scanf("%d", &Qsusu);

printf("Enter the quantity of Alam Kicap Manis :");

scanf("%d", &Qkicap);

printf("Enter the quantity of Tepung Gandum Pelita :");

scanf("%d", &Qtepung);

printf("Enter the quantity of Gula Kasar :");

scanf("%d", &Qgula);

printf("Enter the quantity of Tasty Sardines :");

scanf("%d", &Qsardin);

total= (Qsusu*3.50)+(Qkicap*4.00)+(Qtepung*4.00)+(Qgula*5.40)+(Qsardin*3.70);

printf("FRESH GROCER\n");

printf("Taman Serene, Sepang \n");

printf("\t\t\t\tQuantity\tRM\n");

printf("1\tSihat Susu Pekat Manis\t%d\t\t%.2f\n", Qsusu, susu);

printf("2\tAlam Kicap Manis\t%d\t\t%.2f\n", Qkicap, kicap);


printf("3\tTepung Gandum Pelita\t%d\t\t%.2f\n", Qtepung, tepung);

printf("4\tGula Kasar\t\t%d\t\t%.2f\n", Qgula, gula);

printf("5\tTasty Sardines\t\t%d\t\t%.2f\n", Qsardin, sardin);

printf("\t\t\t\tTotal= %.2f\n", total);

return 0;

}
EXERCISE 4

#include <stdio.h>

#define PriceTart 30.00

#define PriceCookies 28.00

#define PriceCake 20.00

int main()

int OrderNo, QPineappleTart, QAlmondCookies, QFruitCake;

float TartPrice, CookiesPrice, CakePrice, total;

printf("Item\t\tDescription\t\tPrice (RM)\n");

printf("----\t\t-----------\t\t----------\n");

printf("Pineapple Tart\t\t50pieces\t\\t30.00\n");

printf("Almond Cookies\t\t50pieces\t\t28.00\n");

printf("Fruit cake\t\t500g\t\t\t\t20.00\n");

printf("Enter order number :");

scanf("%d", &OrderNo);

printf("Enter the quantity of Pineapple Tart :");

scanf("%d", &QPineappleTart);

printf("Enter the quantity of Almond Cookies :");

scanf("%d", &QAlmondCookies);

printf("Enter the quantity of Fruit Cake :");

scanf("%d", &QFruitCake);
TartPrice = (QPineappleTart*PriceTart);

CookiesPrice = (QAlmondCookies*PriceCookies);

CakePrice = (QFruitCake*PriceCake);

total = (QPineappleTart*PriceTart)+(QAlmondCookies*PriceCookies)+(QFruitCake*PriceCake);

printf("\n\n\t\t**INVOICE**\n");

printf("Order No: %d\n", OrderNo);

printf("Item\t\tQuantity\tPrice (RM)\n");

printf("----\t\t--------\t----------\n");

printf("Pineapple Tart\t%d\t\t%.2f\n", QPineappleTart, TartPrice);

printf("Almond Cookies\t%d\t\t%.2f\n",QAlmondCookies, CookiesPrice);

printf("Fruit cake\t\t%d\t\t\t%.2f\n", QFruitCake, CakePrice);

printf("Total Price(RM)= %.2f", total);

return 0;

You might also like