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.
#include "pch.h"
#include <iostream>
usingnamespace 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;
}
elseif (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;
}
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.
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.