Sie sind auf Seite 1von 11

Functions

4th Week

LAQUI, Eloisa Joyce


C.
BSCE – 1203
1. Using functions, create a program that displays the following menu for
the food items available to take order from the customer:
 B - Burger
 F - French Fries
 P - Pizza
 S - Sandwich

The program inputs the type of the food and quantity. It finally displays
the total charges for the order according to following criteria:
 Burger = 200
 French Fries = 50
 Pizza = 500
 Sandwich - 150
//Laqui, Eloisa Joyce C.
//BSCE - 1203 void sandwhich()
//Week 4 - Activity 1 {
int a,b;
#include <iostream> cout<<"No. of Items: ";
#include <stdlib.h> cin>>a;
#include <conio.h> b = (a*150);
cout<<"Total Amount: PhP"<<b<<endl;
using namespace std; cout<<"You have ordered successfully."<<endl;
}
void burgers ()
{ int main ()
int a,b; {
cout<<"No. of Items: "; char menu;
cin>>a;
b = (a*200); cout<<"Welcome Dear Customer! Here is our menu for today:\n"<<endl;
cout<<"Total Amount: PhP"<<b<<endl;
cout<<"You have ordered successfully."<<endl; cout<<" {B} Burger ~~~~~~~~~~~~~~ PhP 200.00\n {F} French Fries ~~~~~~~~ PhP 50.00\n {P} Pizza
} ~~~~~~~~~~~~~~~ PhP 500.00\n {S} Sandwhich ~~~~~~~~~~~ PhP 150.00\n\n"<<endl;
void fries()
{ cout<<"Place your order here (B,F,P,S):";
int a,b; cin>>menu;
cout<<"No. of Items: "; if (menu=='B')
cin>>a; burgers();
b = (a*50); else if (menu=='F')
cout<<"Total Amount: PhP"<<b<<endl; fries();
cout<<"You have ordered successfully."<<endl; else if (menu=='P')
} pizza();
void pizza() else if (menu=='S')
{ sandwhich();
int a,b; else cout<<"Invalid Order. Please try again!\n"<<endl;
cout<<"No. of Items: ";
cin>>a; cout<<"Enjoy your meal! Thank you and come again!";
b = (a*500);
cout<<"Total Amount: PhP"<<b<<endl; getch ();
cout<<"You have ordered successfully"<<endl; return 0;
} }
1

2
3

4
OUTPUT:

5
2. Program to make a simple
calculator to Add, Subtract, Multiply
and Divide using functions.
//Laqui, Eloisa Joyce C. void m() int main()
//BSCE - 1203 { {
//Week 4 - Activity 2 int a,b,c; char op;

#include <iostream> cout<<"Enter the first number: "; cout<<"Enter the operator (+,-,*,/): ";
#include <stdlib.h> cin>>a; cin>>op;
#include <conio.h> cout<<"Enter the second number: ";
cin>>b; if (op=='+')
using namespace std; c = (a*b); a();
void a() cout<<"Product: "<<c;
{ } else if (op=='-')
int a,b,c; s();
void d()
cout<<"Enter the first number: "; { else if (op=='*')
cin>>a; int a,b,c; m();
cout<<"Enter the second number: ";
cin>>b; cout<<"Enter the first number: "; else if (op=='/')
c = (a+b); cin>>a; d();
cout<<"Sum: "<<c; cout<<"Enter the second number: ";
} cin>>b; else cout<<"Invalid. Try again!";
void s() c = (a/b);
{ cout<<"Quotient: "<<c; getch ();
int a,b,c; } return 0;
}
cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the second number: ";
cin>>b;
c = (a-b);
cout<<"Difference: "<<c;
}
1

2
3

4
OUTPUT:

Das könnte Ihnen auch gefallen