|
Before we move on, take a look at some examples and we'll step through them so you can be sure you're learning all this. Here we go..
#include <iostream.h>
struct food {
int rating; /* Rating, out of ten */
double weight; /* Weight, in Pounds */
int ttc; /* Time To Cook */
int calories; /* Seconds it takes to cook */
};
void main(void)
{
food good; /* A can of Jolt Cola */
food *bad; /* A school "lunch" */
bad = new food; /* Create the school "food" */
good.rating = 10; /* Fill in Jolt Cola's stats */
good.weight = .2;
good.ttc = 0;
good.calories = 150;
bad->rating = 1; /* Fill in School "Food"'s stats */
bad->weight = 5.0;
bad->ttc = 30;
bad->calories = 1400;
if (good.rating > bad->rating)
cout << "I like Jolt Cola more than that icky pseudo-food." << endl;
else
cout << "I like watching my food glow!" << endl;
}
Here's the breakdown: First, a structure named (Only a sick, sick person would change the rating of school food so that it was higher than Jolt Cola, but go ahead and try it for educational value) |