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
Leto [7]
3 years ago
11

Prompt the user for a character and the height of a right triangle. Then, print a triangle of that height using the character en

tered. Validate that the height entered is > 0. If not, ask the user repeatedly until they comply. Hint: Use nested loops Example Input Corresponding output Enter a character: # #Enter a height: 4 ## ###

Computers and Technology
1 answer:
valina [46]3 years ago
8 0

Answer:

Complete code with comments for explanation and output results are given below

Explanation:

#include <iostream>

using namespace std;

int main()

{

   int h;

   char ch;

// prompt the user for a character

   cout << "Enter the character"<<endl;

   cin >> ch;

// prompt the user for the height of the triangle

   cout << "Enter the height of the triangle"<<endl;

   cin >> h;

   // validate the input by checking if it is less or equal to 0

   if (h <= 0)

   {

       cout<<"wrong selection! Enter height again"<<endl;

       cin>>h;

   }

// run two nested loops one for rows and one for columns to print the triangle

   for(int i = 1; i <= h; i++)

   {

       for(int j = 1; j <= i; j++)

       {

           cout <<ch;

       }

       cout << "\n";

   }

   return 0;

}

Output:

Enter the character

%

Enter the height of the triangle

0

wrong selection! Enter height again

9

%

%%

%%%

%%%%

%%%%%

%%%%%%

%%%%%%%

%%%%%%%%

%%%%%%%%%

You might be interested in
Who is the host in super monkey ball?
Savatey [412]

Answer:

Brian

Explanation:

3 0
3 years ago
Write a program to accept radius and find area of circle
Ilya [14]

Answer:

Change it however you'd like

Explanation:

from math import pi

def findArea(rad):

   return (rad**2) * pi

#test

print(f"Area of the circle: {findArea(5)}")

8 0
3 years ago
Read 2 more answers
Write a Python program that uses function(s) for writing to and reading from a file:
swat32

import random

def random_number_file_writer(nums):

   f = open("random.txt", "w")

   i = 0

   while i < nums:

       f.write(str(random.randint(1,500))+"\n")

       i += 1

   f.close()

def random_number_file_reader():

   f = open("random.txt", "r")

   total = 0

   count = 0

   for x in f.readlines():

       total += int(x)

       count += 1

   print("The total of the numbers is "+str(total))

   print("The number of random numbers read from the file is "+str(count))

def main():

   random_number_file_writer(int(input("How many random numbers do you want to generate? ")))

   random_number_file_reader()

main()

I hope this helps!

6 0
3 years ago
Which layer of the OSI model do network administrators typically check first when issues arise?
bazaltina [42]

Answer:

B

Explanation:

Typically I check the physical layer to ensure that the nodes are plugged accordingly.

4 0
2 years ago
Suppose we have a video camera that produces video data at the rate of 2gb per hour. Recording for 15 minutes
saul85 [17]
If it was recording for 15 minutes it would use 0.5gb because 1gb is 30 minutes and so halfing that would be 0.5gb for 15 minutes.
3 0
3 years ago
Other questions:
  • Which of these graphic elements combine text, illustrations, and color?
    14·2 answers
  • What happens when a user updates a record after a developer creates a Workflow Rule declaratively that updates a field on an obj
    6·1 answer
  • Quick Search lets you refine or narrow your search results using links on the right side of the screen. Do a search on nano-mate
    12·1 answer
  • The area on your screen where you can access the tab and menu options for word is called what?
    8·2 answers
  • which telecommunications service allows internet and telephone service to work over the same phone line
    13·1 answer
  • in a deisgn project, what two types of graphics or images is the digital artist respondsible for creating?
    11·1 answer
  • Which of the following is an example of a tax?
    11·1 answer
  • State the functions of all the parts of the computer​
    14·1 answer
  • What would be an ideal scenario for using edge computing solutions?
    6·1 answer
  • which is a correct procedural step for a webpage to render on a user's browser? an information request is sent to an ip address
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!