Write a method in C++ that: generates a stream of random integers between 0 and
ID: 3668786 • Letter: W
Question
Write a method in C++ that:
generates a stream of random integers between 0 and 80
for each random number, prints that many asterisks in a line
keeps generating random numbers until either a number divisible by 11 is generated or a total of 50 numbers has been generated
For example, suppose the numbers 7, 17, 21, 5 and 33 were generated. Then the output would be as follows:
Set up your main program to call this method 3 times. Before the method gets called, give a number of which call you're on, e.g. "Call 1:" and then the method's output. After each call, give a blank line.
Explanation / Answer
#include <iostream>
using namespace std;
int main(){
for(int i = 1; i <= 5; i++){
//generate random number
int randNum = rand() % 30 + 1;
//the nested loop to print asterisks the amount of the randNum
for(int j = 0; j < randNum; j++){
cout<<"*";
}
//new line for each number
cout<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.