Skip to content
Snippets Groups Projects
Commit cb66bab6 authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 5 - Farm.cpp

parent 4f30f41a
No related branches found
No related tags found
No related merge requests found
#include <stdlib.h>
#include <iostream>
using namespace std;
// Declaration of three global variables
int weight=0;
float dailyPrice=0;
float revenue=0;
int weight = 0;
float dailyPrice = 0;
float revenue = 0;
//Prototypes
// Prototypes
void Data_query();
void Calculate_revenue();
void Data_output();
// Function to input the weight and price
void Data_query()
{
cout << "What is the weight? " << endl;
cin >> weight;
cout << "What is the daily price? " << endl;
cin >> dailyPrice;
void Data_query() {
cout << "What is the weight? " << endl;
cin >> weight;
cout << "What is the daily price? " << endl;
cin >> dailyPrice;
}
// Function to calculate the revenue
// Function to calculate the revenue
// by multiplying weight & price
void Calculate_revenue()
{
revenue = weight * dailyPrice;
cout << "Revenue: " << revenue << endl;
void Calculate_revenue() {
revenue = weight * dailyPrice;
cout << "Revenue: " << revenue << endl;
}
int main()
{
int s = 0, input; // declares integer s to zero, is used for the menu
int main() {
int s = 0, input; // declares integer s to zero, is used for the menu
// do-while loop that outputs the menu and calls submenus
do
{
system("cls");
cout << "Welcome to the farm administration" << endl << endl << "Please make your selection in the menu...." << endl << endl << endl;
//The menu
cout << "[1] Data query" << endl;
cout << "[2] Calculate revenue" << endl;
cout << "[0] Exit" << endl<<endl;
cout << "Make a selection: ";
cin >> input;
//Switch loop calls the individual menu items
switch(input)
{
case 1:
{
system("cls");
Data_query(); // Function to create an animal
cout << "Data has been typed in." << endl;
system("pause");
break;
}
case 2:
{
system("cls");
Calculate_revenue();
system("pause");
break;
}
default:
{
cout << "Wrong input!" << endl;
system("pause");
break;
}
}
}while (input != 0);
cout << endl << "Good Bye!" << endl;
return 0;
};
// do-while loop that outputs the menu and calls submenus
do {
system("cls");
cout << "Welcome to the farm administration" << endl << endl << "Please make your selection in the menu...." << endl << endl << endl;
// The menu
cout << "[1] Data query" << endl;
cout << "[2] Calculate revenue" << endl;
cout << "[0] Exit" << endl << endl;
cout << "Make a selection: ";
cin >> input;
// Switch loop calls the individual menu items
switch (input) {
case 1: {
system("cls");
Data_query(); // Function to create an animal
cout << "Data has been typed in." << endl;
cin.ignore();
cin.get();
break;
}
case 2: {
system("cls");
Calculate_revenue();
cin.ignore();
cin.get();
break;
}
default: {
cout << "Wrong input!" << endl;
cin.ignore();
cin.get();
break;
}
}
} while (input != 0);
cout << endl << "Good Bye!" << endl;
return 0;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment