1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Natasha_Volkova [10]
3 years ago
5

Write a short program that allows the user to input a positive integer and then

Computers and Technology
1 answer:
pogonyaev3 years ago
5 0

Answer:

// code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

   int n;

   cout<<"Enter a positive number:";

   // read number

   cin>>n;

   // check number is positive or not

   while(n<0)

   {

   // if number is negative

       cout<<"Wrong input!!"<<endl;

       // ask again to enter again

       cout<<"Enter again:";

       // read number again

       cin>>n;

   }

   // generate random number between 1 to n

   int ran=rand()%n +1;

   // print random number

   cout<<"Random number between 1 to "<<n<<" is: "<<ran<<endl;

return 0;

}

Explanation:

Read a number from user.Then if input number is negative then ask user to enter a positive number again.After this generate a random number between 1 to n.Print that random number.

Output:

Enter a positive number:-12

Wrong input!!

Enter again:9

Random number between 1 to 9 is: 2

You might be interested in
The _______ number system allows digital devices to represent virtually any number simply by using 0s and 1s.â
zhuklara [117]
The answer is <span>Digital data 

</span>
4 0
3 years ago
What's the best way to use a lectern during your speech?
valentina_108 [34]

<span>Make eye contact look at everyone ur speaking to not just one person speak loud and clearly make sure your understandable</span>
6 0
3 years ago
Read 2 more answers
What type of hardware enables users to interact with a computer? Check all that apply. the CPU the hard disk drive the keyboard
valentina_108 [34]

Answer:

the keyboard

the monitor

the mouse

Explanation:

just took test

6 0
3 years ago
Read 2 more answers
Software that interpret commands from the keyboard and mouse is known as the
goldfiish [28.3K]
The Operating system kernel, a component of all operating systems, interprets these signals by the use of a device driver, so the answer to your questions is a "driver".    <span />
3 0
3 years ago
Sensors send out ............ signals​
son4ous [18]

Answer:

mhmm................... ok

3 0
3 years ago
Other questions:
  • How do u change the level of education on Brainly. cuz i just finished elementry
    9·2 answers
  • What is the on board storage C:
    15·1 answer
  • IblMessage.txt=welcome to fiji.what is the error in the coding and what type of error is it?(explain)​
    5·1 answer
  • The component that allows you to make a paper-based copy of a body of text is the _____.
    12·1 answer
  • Which of the following best describes the 7x7 PowerPoint rule
    8·1 answer
  • 9. What is the difference between a hand-drawn sketch, a working drawing, and a 3D model?
    14·1 answer
  • (Reverse number) Write a program that prompts the user to enter a four-digit inte- ger and displays the number in reverse order.
    9·1 answer
  • Which best compares portrait and landscape orientations?
    7·1 answer
  • Write an SQL statement to display for every restaurant the name of the restaurant (where the name of the restaurant consists of
    10·1 answer
  • the application you attempted to authenticate to is not authorized to use cas. contact your cas administrator to learn how you m
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!