Subroutines program

Dec 1, 2018 at 3:21pm
Can someone explain to me how this program works, I've ran it and it works but I don't understand how it actually works



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

//

#include "pch.h"
#include <iostream>
using namespace std;
// Cooking heat can be high or low
enum Heat { low, high };
// Create a struct to simulate order
struct Order {
	bool cooked = false;
};
// Subroutine for frying order
void fry(Order order, Heat heat) {
	cout << "Frying order at " << heat << " temperature." << endl;
	if (heat == low) {
		cout << "Frying order at low" << endl;
	}
	else if (heat == high) {
		cout << "frying order at high" << endl;
	}
}



int main()
{
	// Create order
	Order order = Order();
	// Print intro message
	cout << "Cooking order:" << endl;
	// Fry order
	fry(order, low);
	fry(order, high);
	
	
		cout << "Order is ready" << endl;
	// End program
	system("pause");
	return 0;
}





Last edited on Dec 1, 2018 at 3:42pm
Dec 1, 2018 at 3:27pm
I've ran it and it works

It doesn't even compile.
Dec 1, 2018 at 3:42pm
should do now.
Dec 1, 2018 at 8:44pm
All the program does right now is output a message. order on line 29 is never used by anything in the program. The fry() function outputs a different message based on whether the heat parameter is "high" or "low."
Dec 1, 2018 at 9:16pm
1
2
Subroutine for frying order
void fry(Order order, Heat heat)


But why is there an Order and order and Heat and heat

and what is the point of using a subroutine - what is it
Last edited on Dec 1, 2018 at 9:17pm
Dec 1, 2018 at 10:02pm
closed account (z05DSL3A)
http://www.cplusplus.com/doc/tutorial/functions/
Dec 2, 2018 at 12:33am
This is a really bad code example to learn from because it's incomplete. It's no wonder you're confused.

Rocketboy wrote:

But why is there an Order and order and Heat and heat

and what is the point of using a subroutine - what is it


I don't know why there is an Order. It does literally nothing in this program. It looks like something the programmer intends to build upon later.

"Order" is a data structure. It's normally used to group different types of data together, but here there's only one piece of data in the struct, so it's pointless. "order" is the name of a variable of type "Order."

http://www.cplusplus.com/doc/tutorial/structures/

"Heat" is a custom type that can have the value "high" or "low." "heat" is the name of a variable of type "Heat."

See enums on this page: http://www.cplusplus.com/doc/tutorial/other_data_types/
Topic archived. No new replies allowed.