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]
2 years ago
5

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

Computers and Technology
1 answer:
pogonyaev2 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
What specific type of DNS query instructs a DNS server to process the query until the server replies with an address that satisf
Kaylis [27]
Unsure how it is to be answered
8 0
3 years ago
HELP ASAP DUE IN 10 MINUTES!!! HELP!!!!!<br> Problem solver<br> Logical<br> Innovative
marshall27 [118]
The first one is problem solver, the second one is Innovative, and the third one is logical.
6 0
3 years ago
Read 2 more answers
Que implicaciones sociales puede tener la robótica
wolverine [178]
Según estos estudios, el impacto de los robots en la productividad ya se compara con la contribución de las máquinas de vapor en el pasado. ... Algunos de los aumentos en la productividad que se derivan de la densificación de los robots se comparten con los trabajadores mediante el pago de salarios más altos.
8 0
2 years ago
Which statement will add a string to the string pool?
Alecsey [184]

Answer:

string newstring="hello"

7 0
1 year ago
Select the data type for each example below. <br> Possible answers<br> -Int<br> -float <br> -string
Shkiper50 [21]

Answer:

2.5 = float

'2.5' = str

3 = int

Explanation:

The data type: "float" is used for positive or negative decimals.

The data type: "str" is used for a sequence of letters, numbers, or symbols. Since the decimal used apostrophes, this means it's a character literal.

The data type: "int" is used for any positive or negative whole number.

7 0
2 years ago
Other questions:
  • Steve is proofreading his memo and he notices that he has typed a phrase twice. Steve should _____.
    5·2 answers
  • How does information technology most benefit people’s personal and professional lives?
    9·2 answers
  • Problem 3. Consider the following recurrence, defined for n a power of 4 (for the time of some algorithm): T(n) = 3 if n = 1 2T(
    5·1 answer
  • A network slows down when a network card is locked in a perpetual mode
    12·2 answers
  • All of the following are aspects of the search process except?
    6·2 answers
  • To maintain her audience's confidence in her, what should kiara not do while delivering her presentation?
    10·1 answer
  • Computer crimes are a big concern since the creation of innovative technological advances; which is/are examples of computer cri
    13·2 answers
  • Describe FIVE distinct features of multi-threaded programming. Your answer should be language independent. g
    9·1 answer
  • Holi alguien sabe como cambiar el gamertag en XBox App (para iOS)?
    9·1 answer
  • Explain why it is important that the device registration is the last thing that is done in the initialization routine of a devic
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!