Programming Fundamentals
Programming Fundamentals
Roll #: CTAI-040
LAB 05
You must have seen the question before deleting anything like “Are you sure to delete [Y/y] /
[N/n] ? Create a program that asks for this question if user enters Y or y it prints “Deleted
successfully”. If the user enters N or n it prints “Delete cancelled” otherwise it prints choose the
right option using switch statement.
#include<stdio.h>
int main(void){
char c;
switch(c){
case 'Y':
case 'y':
printf("\nDeleted successfully.");
break;
case 'N':
case 'n':
printf("\nDeletion cancelled.");
break;
default:
printf("\nPlease enter a valid command.");
break;
}
}
Write a program to control a coffee machine. Allow the user to input the type of coffee as B for
Black and W for White. Ask the user if the cup size is double and if the coffee is manual. The
following table details the time chart for the machine for each coffee type. Display a statement
for each step. If the coffee size is double, increase the baking time by 50 percent. Use functions
to display instructions to the user and to compute the coffee time.
#include<stdio.h>
int main(void) {
white_coffee_time = 76.0;
black_coffee_time = 105.0;
printf("\n>>>");
case 'W':
case 'w':
switch(manual){
case 'Y':
case 'y':
break;
case 'N':
case 'n':
break;
default:
return 1;
break;
case 'B':
case 'b':
switch(manual){
case 'Y':
case 'y':
case 'N':
case 'n':
break;
default:
return 1;
break;
default:
return 1;
return 0;
Write a program in which user enters his NTS and F.Sc marks and your program will help
student in selection of university. Based on these marks Student will be allocated a seat at
different department of different university.
Oxford
IT: Above 70% in Fsc. and 70 % in NTS
Electronics: Above 70% in Fsc. and 60 % in NTS
Telecommunication Above 70% in Fsc. and 50 % in NTS
MIT
IT: 70% - 60 % in Fsc. and 50 % in NTS
Chemical: 59% – 50 % in Fsc. and 50 % in NTS
Computer: Above 40% and below 50 % in Fsc. and 50 % in NTS
#include <stdio.h>
int main(void) {
scanf("%f", &nts);
scanf("%f", &fsc);
printf("\nYou can get admission in the following university (s) and in the following field
(s): ");
case 1:
break;
case 1:
break;
break;
switch ((fsc_perc >= 70 && fsc_perc <= 60) && (nts_perc >= 50)) {
case 1:
break;
switch ((fsc_perc >= 59 && fsc_perc <= 50) && (nts_perc >= 50)) {
case 1:
break;
switch ((fsc_perc >= 40 && fsc_perc <= 50) && (nts_perc >= 50)) {
case 1:
break;
return 0;
Using IF and Switch statement, write a program that displays the following menu for the
food items available to take order from the customer:
B= Burger (Rs. 200)
F= French Fries (Rs. 50)
P= Pizza (Rs. 500)
S= Sandwiches(Rs. 150)
The costumer can order any combination of available food. The program first ask to
enter the no of types of snacks i.e. 2, 3 or 4 then it ask to enter the choice i.e. B for
Burger and then for quantity. The program should finally display the total charges for the
order.
#include <stdio.h>
switch (snack) {
case 'b':
price = 200;
break;
case 'f':
price = 50;
break;
case 'p':
price = 500;
break;
case 's':
price = 150;
break;
default:
printf("\nInvalid initial provided.");
return -1;
}
int main(void) {
int no_of_snacks, snackoneamt, snacktwoamt, snackthreeamt, snackfouramt,
snackonetotal, snacktwototal, snackthreetotal, snackfourtotal, totalamt;
char snackone, snacktwo, snackthree, snackfour;
printf("\nHow many number snacks would you like to order from the following\n>>>
");
scanf("%d", &no_of_snacks);
switch (no_of_snacks) {
case 1: //for only one choice of order
printf("\nEnter the initial of the snack that you want to order:");
scanf(" %c", &snackone);
printf("\nProvide the quantity: ");
scanf("%d", &snackoneamt);
printf("\nYour receipt:\n");
printf("%d ", snackoneamt);
displayitem(snackone);
printf("(s) = %d PKR\n", snackonetotal);
printf("Total amount = %d PKR", totalamt);
break;
printf("\nEnter the initial of the second snack that you want to order:");
scanf(" %c", &snacktwo);
printf("\nProvide the quantity of the second snack: ");
scanf("%d", &snacktwoamt);
printf("\nEnter the initial of the third snack that you want to order:");
scanf(" %c", &snackthree);
printf("\nProvide the quantity of the third snack: ");
scanf("%d", &snackthreeamt);
printf("\nYour receipt:\n");
printf("%d ", snackoneamt);
displayitem(snackone);
printf("(s) = %d PKR\n", snackonetotal);
printf("%d ", snacktwoamt);
displayitem(snacktwo);
printf("(s) = %d PKR\n", snacktwototal);
printf("%d ", snackthreeamt);
displayitem(snackthree);
printf("(s) = %d PKR\n", snackthreetotal);
printf("Total amount = %d PKR", totalamt);
break;
printf("\nEnter the initial of the second snack that you want to order:");
scanf(" %c", &snacktwo);
printf("\nProvide the quantity of the second snack: ");
scanf("%d", &snacktwoamt);
printf("\nEnter the initial of the third snack that you want to order:");
scanf(" %c", &snackthree);
printf("\nProvide the quantity of the third snack: ");
scanf("%d", &snackthreeamt);
printf("\nEnter the initial of the fourth snack that you want to order:");
scanf(" %c", &snackfour);
printf("\nProvide the quantity of the fourth snack: ");
scanf("%d", &snackfouramt);
printf("\nYour receipt:\n");
printf("%d ", snackoneamt);
displayitem(snackone);
printf("(s) = %d PKR\n", snackonetotal);
printf("%d ", snacktwoamt);
displayitem(snacktwo);
printf("(s) = %d PKR\n", snacktwototal);
printf("%d ", snackthreeamt);
displayitem(snackthree);
printf("(s) = %d PKR\n", snackthreetotal);
printf("%d ", snackfouramt);
displayitem(snackfour);
printf("(s) = %d PKR\n", snackfourtotal);
printf("Total amount = %d PKR", totalamt);
break;
default:
printf("\nInvalid number of snacks provided.");
return 1;
}
return 0;
}