Subroutine and bool

Can someone explain to me how this program works, I've already ran it and got the results but I don't understand how it works, especially the bool part.


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
#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;
}
closed account (SECMoG1T)
from my point of view, the struct called Order is not used anywhere in your program leave alone the bool, the one who wrote it just passed order parameters and never used them, maybe he/she meant to set the bool cooked after sometimes to indicate an order is complete but somehow forgot.

so the code above is equivalent to this:
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
#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( 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()
{
	
	// Print intro message
	cout << "Cooking order:" << endl;
	// Fry order
	fry( low);
	fry(high);


		cout << "Order is ready" << endl;
	// End program
	system("pause");
	return 0;
}
Last edited on
But how does the program actually work? Why use [code] void fry(Heat heat), whats the difference between them? I know the enum is Heat but what is heat. And why use a subroutine? what is the point in it? And I don't understand why Struct is used because I thought that was if you have multiple different things, e.g. short, int, double, not just one type.
Last edited on
In my opinion it's a stupid meaningless program. Forget about it. Get a good book and start from the beginning.
What book do you recommend? I need something that explains things in simple terms and most books explain things like I should already know.
closed account (SECMoG1T)
i agree with @tqb , it is a confused piece of code lol, get a nice beginner friendly book.
Topic archived. No new replies allowed.