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

Update Solution Exercise 5 - Farm.cpp

parent f995593e
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 number = 0;
string type;
int weight = 0;
float dailyPrice = 0;
float revenue = 0;
bool inStock;
// Prototypes
void Create_Animal();
void Show_Animal();
void Sell_Animal();
// Function to create
void Create_Animal() {
cout << "Please type in the number of the animal: ";
cin >> number;
cout << endl;
cout << "Please type in the type of the animal: ";
cin >> type;
cout << endl;
cout << "Please type in the weight of the animal: ";
cin >> weight;
cout << endl;
inStock = true; //Tier ist im Bestand
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;
}
// Function to show the data
void Show_Animal() {
cout << "Animal number: " << number << endl;
cout << "Animal type: " << type << endl;
cout << "Animal weight: " << weight << endl;
cout << "In stock? (1 = yes, 0 = no): " << inStock << endl;
// Function to calculate the revenue
// by multiplying weight & price
void Calculate_revenue() {
revenue = weight * dailyPrice;
cout << "Revenue: " << revenue << endl;
}
//Function to sell
void Sell_Animal(int nr)
{
if(number == nr && inStock == 1)
{
cout << "What is the daily price?"<< endl;
cin >> dailyPrice;
revenue = revenue + (weight*dailyPrice);
cout << "Total revenue: " << revenue << endl;
inStock = false;
cout << endl << endl;
}
else if (number == nr && inStock == 0)
{
cout << "Animal with the number " << nr << " is in stock." << endl;
}
else
{
cout << "Animal with the number " << nr << " is not in stock." << endl;
}
} ;
int main() {
int s = 0, input, nr; // declares integer s to zero, is used for the menu
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"); //Clears the screen for windows-systems. For unix, use system("clear"); - you can also omit it
cout << "Welcome to the farm administration" << endl << endl << "Please make your selection in the menu...." << endl << endl << endl;
// The menu
cout << "[1] Create animal" << endl;
cout << "[2] Show animal" << endl;
cout << "[3] Sell animal" << endl;
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");
Create_Animal(); // Function to create an animal
cout << "Animal has been created." << endl;
Data_query(); // Function to create an animal
cout << "Data has been typed in." << endl;
cin.ignore(); //In windows you can use alternatively system("pause");
cin.get();
break;
}
case 2: {
system("cls");
Show_Animal();
Calculate_revenue();
cin.ignore();
cin.get();
break;
}
case 3: {
system("cls");
cout << "Type in animal number: " << endl;
cin >> nr;
Sell_Animal(nr);
system("pause");
break;
}
default: {
cout << "Wrong input!" << endl;
cin.ignore();
......
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