C functions and random numbers C Function random numbers Fol

C++ functions and random numbers
C++ (Function random numbers) Follow the format Write a function Noodles(), with int parameter minutes, and void return type. Print \"N minutes\" for each minute in decreasing order, where N is the number of minutes, followed by \"Done\". End with a newline. The number of minutes is generated from a random number generator that selects between 1-3 minutes. The seed for the random number generator is input by the user. Example output for minutes = 2:2 minutes 1 minutes Done. #include #include using namespace std; int main() {int minutes = 0; int seed; cin >> seed; srand();//add random number generator to determine the number of minutes to cook the noodles Noodles(minutes); return 0://write Noodles() function to countdown the time until the noodles arc done.

Solution

#include <iostream>
#include <cstdlib>
using namespace std;
//Noodles method for printing the number of minutes to cook the noodles
void Noodles(int mins){
   // while loop to iterate the minutes and decreasing
while(mins>0){
cout<<mins<<\" minutes \";
mins--;
}
cout<<\" Done.\";
   //Noodles method ends
}

int main() {
   // your code goes here
   int minutes=0;
   int seed;
   cin>>seed;//getting the seed value;
   srand(seed);
   minutes=rand() % 3 +1;// to get numbers from 1-3.
   cout<<\"Output for minutes = \"<<minutes<<\": \";
   Noodles(minutes);//call method Noodles
   return 0;
}
-----------------output-----------
2   
Output for minutes = 1: 1 minutes Done.   
1   
Output for minutes = 2: 2 minutes 1 minutes Done.
--------------output ends--------------

//Note: Feel free to ask question/doubts. God bless you!!

C++ functions and random numbers C++ (Function random numbers) Follow the format Write a function Noodles(), with int parameter minutes, and void return type. P

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site