C programming The intent of this assignment is to get you to

C++ programming

The intent of this assignment is to get you to create user defined functions and also make use of repetition, so you must use each in order to get credit for the program working. Introduce your program to the user and allow the user to continue to display Halloween messages as many times as they want (think repetition).

Each time they continue, a random message should be displayed on the screen. There should be at least 10 different messages that can be randomly selected. (check out rand() function). Consider messages such as Boo!, Creak!, Grrr!, etc. Each message should be displayed centered in a nice box. (i suggest creating a user defined function for the display).

Remember this is a C++ program.

Solution

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

using namespace std;

int main() {
   srand(time(NULL));
int n;
//list of messages here
string msgs[] = {\"message1\",\"message2\",\"message3\",\"message4\",\"message5\",\"message6\",\"message7\",\"message8\",\"message9\",\"message10\"};
  
char choice;
choice = \'y\';
//using while loop taking input from user multiple times
while(choice == \'y\'){
   n = rand() % 10 + 1;       //randomly generating numbers between 1 and 10
       cout << msgs[n-1] << endl;   //printing the message  
   cout << \"\ Do you wish to continue : (y/n)\";
   cin >> choice;
}

}

Output:

C++ programming The intent of this assignment is to get you to create user defined functions and also make use of repetition, so you must use each in order to g

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site