asher63 (asher63) wrote,
asher63
asher63

  • Mood:

Success with my novice's command of C++.

And I know you're all excited about this as I am: I just wrote a successful script to test the user's ability to add single-digit hexadecimal numbers.



#include
#include
#include
using namespace std;
int i, r1, r2;
int sum, userInput;
int main()
{
for(i = 0; i < 16; i++)
{
srand(time(0));
r1 = (rand() % 16);
r2 = (rand() % 16);
do
{
cout << hex << r1 << endl;
cout << hex << r2 << endl;
sum = r1 + r2;
cin >> hex >> userInput;
if(userInput != sum)
cout << "TRY AGAIN\n";
}
while(userInput != sum);
cout << "good" << endl;
}
cout << "done!" << endl;
return 0;
}

ETA: Ouch! Just realized the stuff in angle brackets doesn't show up in html.

That's:

#include [iostream]
#include [ctime]
#include [cstdlib]
Tags: geekery
Subscribe

  • Clock.

    Well, nothing lasts forever, and at exactly 8:00 this morning I was winding the antique mantel clock and felt the key suddenly snap out of my hand. I…

  • Monday evening.

    SOCIETY. Later this week, I'll be hosting a meeting of a conservative-leaning group that I've been a member of for several years. In the past, we met…

  • Thursday evening.

    AUTOMOTIVE. It's been a little while since I posted a journal entry. The biggest development in my day-to-day life is that I am finally a car owner…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments