#include<stdio.h> int main() { int i = 1,n,bill=0,opt,qty,total,menu; printf("\t\t\t\t\t*****************************************\n"); printf("\t\t\t\t\t||||||WELCOME TO OUR ONLINE SHOPPING||||||\n"); printf("\t\t\t\t\t*****************************************\n"); printf("\n\n"); printf("--PLEASE ENTER:[ 1 ] TO GET INTO OUR MENU LIST-- :"); scanf("%d",&menu); if(menu==1) { printf("\n\t\t\t\t\t_____ _____"); printf("\n\t\t\t\t\t_____THESE ARE PRODUCTS AVAILABE FOR YOU_____\n\n"); printf("1.) Dairy Milk Silk - 150gms : 120/-\n"); printf("2.) Lays - 100gms : 30/- \n"); printf("3.) Unibic-Biscuits - 100gms : 50/- \n"); printf("4.) BELL-RICEBAG - 10kgs : 500/-\n"); printf("5.) Heritage-Milk packet - 1lit : 40/- \n\n"); printf("please enter the number of products you require from the above menu :\t"); scanf("%d",&n); if(n<=5) { printf("\t\t\t\t\t\t______________ _______________\n"); printf("\t\t\t\t\t\t______________ BILL _______________\n\n\n"); for(i=1;i<=n;i++) { printf("please enter your product %d :" ,i); scanf("%d",&opt); switch(opt) { case 1: { printf("you have choosen Dairy Milk Silk"); printf("\nQUANTITY-->:"); scanf("%d",&qty); total = 120*qty; printf("\nTotal on this product :%d/-\n",total); bill +=total; break; } case 2: { printf("you have choosen Lays"); printf("\nQUANTITY-->:"); scanf("%d",&qty); total = 30*qty; printf("\nTotal on this product :%d/-\n",total); bill +=total; break; } case 3: { printf("you have choosen Unibic-Biscuits"); printf("\nQUANTITY-->:"); scanf("%d",&qty); total = 50*qty; printf("\nTotal on this product :%d/-\n",total); bill +=total; break; } case 4: { printf("you have choosen Bell-Ricebag"); printf("\nQUANTITY-->:"); scanf("%d",&qty); total = 500*qty; printf("\nTotal on this product :%d/-\n",total); bill +=total; break; } case 5: { printf("you have choosen Heritage Milk Packet"); printf("\nQUANTITY-->:"); scanf("%d",&qty); total = 40*qty; printf("\nTotal on this product :%d/-\n",total); bill +=total; break; } } } } else { printf("\n\n please enter a valid number of products you required from the above Menu"); } } else { printf("\n\ninvalid input please enter the number-->[1]"); } printf("\n\n\t\t\t\t\t*************TOTAL BILL*************\n"); printf("\n\t\t\t\t\t\tYOUR TOTAL BILL : %d\n\n",bill); printf("\t\t\t\t\t*****************THANK YOU*******************\n"); printf("\t\t\t\t\t------Have A Nice Day & Visit Again------"); return 0; }
Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!
OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.
#include <stdio.h>
int main()
{
char name[50];
printf("Enter name:");
scanf("%s", name);
printf("Hello %s \n" , name );
return 0;
}
C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.
When ever you want to perform a set of operations based on a condition if-else
is used.
if(conditional-expression) {
// code
} else {
// code
}
You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to if-else-if ladder.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
data-type array-name[size];
data-type array-name[size][size];
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Two types of functions are present in C
Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,
User defined functions are the ones which are written by the programmer based on the requirement.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
//code
}