Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VHB C++ DE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VHB Cpp
VHB C++ DE
Commits
cb66bab6
Commit
cb66bab6
authored
7 months ago
by
Rudi Buss
Browse files
Options
Downloads
Patches
Plain Diff
Update Solution Exercise 5 - Farm.cpp
parent
4f30f41a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Part 1/4. Control structures/Solutions/Solution Exercise 5 - Farm.cpp
+61
-67
61 additions, 67 deletions
...ntrol structures/Solutions/Solution Exercise 5 - Farm.cpp
with
61 additions
and
67 deletions
Part 1/4. Control structures/Solutions/Solution Exercise 5 - Farm.cpp
+
61
−
67
View file @
cb66bab6
#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
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment