I have to do this excercise:
A common punishment for school children is to write out the same sentence multiple times. Write a C++ stand-alone program that will write out the following sentence one hundred times: “I will always use objectoriented design.” Your program should number each of the sentences and it should “accidentally” make eight different random-looking typos at various points in the listing, so that it looks like a human typed it all by hand.
My knowledge is limited with C random numbers. I have tried this with no success. I can't get 8 errors. As we can see, I get Random errors with the "typo".
Here is my buggy code:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
string strPunish = "I will always use objectoriented design.";
int randFrom = 1;
int randTo = 100;
int typoCounter = 0;
srand(time(NULL));
int randNumber = randFrom + ( std::rand() % ( randTo - randFrom + 1 ) );
for (int i = 1; i <= 100; i++)
{
if ((i == randNumber) && (typoCounter != 8))
{
randFrom = i;
randNumber = randFrom + ( std::rand() % ( randTo - randFrom + 1 ) );
string strTypo = strPunish;
int randTypo = 0 + ( std::rand() % ( strTypo.length() - 0 + 1 ) );
strTypo.insert(randTypo, "TYPO");
cout << i << ": " << strTypo << endl;
typoCounter++;
}
else
cout << i << ": " << strPunish << endl;
}
return EXIT_SUCCESS;
}