Question

C++ Write a complete program that will prompt the user for a digit in the range...

C++

Write a complete program that will prompt the user for a

digit in the range 5 to 15. Using that digit to determin scale

display the graphic shown below. Your program must use a nested loop.

You may not use the string class

SAMPLE RUN:

Input an integer in the range 5 to 20: 100

Incorrect. The number is out of range.

Input an integer in the range 5 to 20: 10

*

**

***

****

*****

******

*******

********

*********

**********

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
   int n;
   while(1)
   {
   cout<<"Input an integer in the range of 5 to 15: ";
   cin>>n;
   if(n>=5 && n<=15)
   {
       for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<" ";
}
break;
   }
   else
   {
       cout<<"The number is out of range"<<endl;
   }
}
return 0;
}

Sample output:

Users Executingl-Dev-C++5.11 Eile Edit Search View Project Execute Tools AStyle Window Help globals) Project Classes Debug pattern.cpp 1.cppass1.4.cpp if(n>#5 && n(#15) CAUsersoDesktoptHomeworkLiblpattem.exe Input an integer in the range of 5 to 15: 2 The number is out of range Input an integer in the range of 5 to 15: 4 The number is out of range Input an integer in the range of 5 to 15: 12 ae Compiler Resouro Process exited after 6.891 seconds with return value e Press any key to continue . shorten compiler paths Col: 50 Sel: 0 Lines: 29 Length: 420 Insert Done parsing in 0.015 seconds 11:29 PM Type here to search 31-lan-19 2

Logic behind the code:

Here an infinite while loop is used inorder to print the patttern.

Once the value which is in the range is entered then the infinite while loop will terminate and the required pattern will be printed.

The value of n is checked inside an if condition.

If n value does not meet our condition then execution will go to else.

Add a comment
Know the answer?
Add Answer to:
C++ Write a complete program that will prompt the user for a digit in the range...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete program that will prompt the user for an integer You must keep asking...

    Write a complete program that will prompt the user for an integer You must keep asking the user until they give you a number that is greater than 700. Once they give a valid number, display all multiples of 7 from 7 to that number inclusively). You may assume the user will give you correct type of input, but your code must continue to prompt them until they give a number greater than 700.

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Write a complete C++ program that do following. 1) Read a positive integer from the user...

    Write a complete C++ program that do following. 1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0. 2) Create a size 10 array as counters for digits 0 - 9. 3) Use a while loop for processing a) Single out the current last digit using modular 10 technique b) Increment the corresponding counter through the index derived in a). 4) At the...

  • Write a program that asks the user to input a 4-digit integer and then prints the...

    Write a program that asks the user to input a 4-digit integer and then prints the integer in reverse. Your program needs to implement a function reverse that will take in as input the 4-digit number and print it out in reverse. Your code will consist of two files: main.s and reverse.s. Main.s will ask for the user input number and call the function reverse. For ARM/Data Structure needs to be able to run on Pi Reverse.s will take in...

  • Write a complete program in assembly line that:    1. Prompt the user to enter 10...

    Write a complete program in assembly line that:    1. Prompt the user to enter 10 numbers.    2. save those numbers in a 32-bit integer array.    3. Print the array with the same order it was entered.    3. Calculate the sum of the numbers and display it.    4. Calculate the mean of the array and display it.    5. Rotate the members in the array forward one position for        9 times. so the last...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • C++ Loops homework Prompt the user for a desired password, input the password. Your program may...

    C++ Loops homework Prompt the user for a desired password, input the password. Your program may assume without checking that there is no input failure and that the password contains no white space. Let's say the rules for a legal password are: # chars must be in [4, 8] # digs must be >= 2 The password must contain at least one letter of each case The password must contain at least one char that's not a letter or digit...

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9.

     4.18 LAB: Checker for integer string Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Exx If the input is: 1995 the output is: yes Ex If the input is: 42,000 1995! the output is no Hint: Use a loop and the Character isDigitO function. 418.1: LAB: Checker for integer string

  • Program : Write a complete C++ program that Input: Read a positive integer from the keyboard...

    Program : Write a complete C++ program that Input: Read a positive integer from the keyboard (user) with proper prompt text and save it to a variable. The integer have up to five digits. Processing: From the right most digit, extract every digit from the input integer using modular operator %then save the digit to a separate variable. Remove the right most digit from the integer using integer division operator /. Repeat above two steps till all digits have been...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT