//Point-of-Sale System #include<studio.h> void main(void) { int code, qty; float price; printf("=========="); printf("PUREGOLD MENU\n"); printf("==========\n\n"); printf("Dairy\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("D1\t\tMilk\t\t100.00\n"); printf("D2\t\tCheese\t\t200.00\n"); printf("D3\t\tYogurt\t\t45.00\n\n"); printf("MEAT\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("M1\t\tChicken\t\t160.00\n"); printf("M2\t\tBeef\t\t300.00\n"); printf("M3\t\tPork\t\t200.00\n\n"); printf("SNACKS\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("S1\t\tChips\t\t30.50\n"); printf("S2\t\tCookies\t\t120.00\n"); printf("S3\t\tPopcorn\t\t65.00\n\n"); printf("BEVERAGES\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("B1\t\tSoda\t\t15.50\n"); printf("B2\t\tCoffee\t\t75.00\n"); printf("B3\t\tTea\t\t40.75\n\n"); printf("PRODUCE\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("P1\t\tApples\t\t20.00\n"); printf("P2\t\tBananas\t\t50.75\n"); printf("P3\t\tLettuce\t\t75.50\n\n"); printf("FROZEN FOODS\n\n"); printf("CODE\t\tMENU\t\tPRICE\n"); printf("F1\t\tHotdogs\t\t350.00\n"); printf("F2\t\tNuggets\t\t750.75\n"); printf("F3\t\tVeggies\t\t250.50\n\n"); printf("nEnter Code\t: "; scanf("%d", &code); printf("\nEnter Quantity: "); scanf("%d", &qty); switch (code) { case D1: price = 100.00; break; case D2: price = 200.00; break; case D3: price = 45.00; break; case M1: price = 160.00; break; case M2: price = 300.00; break; case M3: price = 200.00; break; case S1: price = 30.50; break; case S2: price = 120.00; break; case S3: price = 65.00; break; case B1: price = 15.50; break; case B2: price = 75.00; break; case B3: price = 40.75; break; case P1: price = 20.00; break; case P2: price = 50.75; break; case P3: price = 75.50; break; case F1: price = 350.00; break; case F2: price = 750.00; break; case F3: price = 250.00; break; } amt = price * qty; printf("nAmount: %.2f", amt); }
Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++
and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming 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);
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. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}