FINALLY UNDERSTAND CLASSES AND STRUCTS.
WTF HOW DID I NOT GET IT BEFORE?
C++ code:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>
using namespace std;
struct Stoast
{
string strmbutter_confirmation;
} qtoast;
int main()
{
srand( time(NULL) );
string strname;
int a = rand() % 10 + 2;
int b = rand() % 30 + 10;
cout << "\nHow much butter is there on our toast?" << endl;
cout << "--------------------------------------" << endl;
cout << "Enter your name: ";
getline(cin,strname);
cout << "\nTo decide whether your toast has butter or not,\nanswer this question: ";
cout << "What is " << a << " + " << b << "?" << endl;
int ianswer;
cin >> ianswer;
int iresultant = (a + b) - ianswer;
cout << "Answer: " << ianswer << endl;
if (iresultant == 0)
{
cout << "Butter for you good sir!" << endl;
qtoast.strmbutter_confirmation = "Yes";
} else if (iresultant >= -2 && iresultant <= 2)
{
if (iresultant < 0)
{
iresultant *= -1;
}
cout << "Only " << iresultant << " out, a small amount of butter for you!" << endl;
qtoast.strmbutter_confirmation = "Some";
} else
{
cout << "Way off, you'll be granted no butter at all!" << endl;
qtoast.strmbutter_confirmation = "No";
}
cout << "Does " << strname << " have butter?: " << qtoast.strmbutter_confirmation << endl;
cout << endl;
return 0;
}
Last edited by Fear; May 30, 2013 at 11:35 AM.