I had an assignment that required us to generate a three digit number twice so a student can add them together and then check their work. I am still very, very new to C++ and my class regretfully provided no information on how to even do this. He provided no videos, articles, or anything on randomly generating numbers, how to secure a specific number of digits, or even how to add them together.
The following is the code I cobbled together, as crude as it is. I cannot guarantee three digits. Every now and then, it will be a two digit number. I have already emailed him to see if he can point me in a correct direction, but I am not optimistic. I was thinking there would be some way I could set a minimum value, but after hours of searching for this, I could not find an answer.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std; //This is so I do not have to type std::
int main(void)
{
int set1;
int set2;
int sum=0;
srand((unsigned) time(NULL)); // sets the random seed to provide different number utilizing the time of the computer
set1 = rand() % 999 + 1; //creates a randomly generated three digit number
set2 = rand() % 999 + 1; //created a randomly generated three digit number
cout << "\n\n\n Are you ready for some math practice?\n\n\n";
cout.width(8); //sets width of the columns to align everything
cout << set1 << "\n"; //prints first generated set
cout << " + ";
cout << set2 << "\n"; //[rints second generated set
cout << "---------\n";
cout << "\n\n\n";
sum = set1 + set2; //add the two generated sets together
cout << "Try to solve the problem. Have you got it?\n";
system("Pause"); //waits for student to press enter to continue
cout << "\n\n\n";
cout << "The answer is: ";
cout << sum; //displays sum of two numbers