Question

4. Write a main function that gets a number, which represents the height and a character/symbol and draws a triangle of the character by calling the functions defined in 1, 2, and 3 above. SAMPLE RUN Enter a number between 3 and 7 2 Invalid val Enter a number between 3 and 7 5 Enter either or Invalid symbol Enter either or & Invalid symbol Enter either or

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

#include <iostream.h>
#include <conio.h>

int main()
{
int height;
char ch;
cout << "Enter number of height: ";
cin >> height;
if(height == 3 || height==4 || height==5)
{
   cout << "enter symbol :";
   cin >> ch;
   if(ch == '*'|| ch =='#' )
       {
       for(int i = 1; i <= height; ++i)
       {
           for(int j = 1; j <= i; ++j)
           {
           cout << ch ;
           }
           cout << "\n";
           }
       }
else {
cout << "invalid ";
cout << "\n";
}

}
else {
cout << "invalid";
cout << "\n";
}
getch();
}Enter number of height: 4 enter symbol* He Enter number of height: 3 enter symbol :# Enter number of height: 6 invalid Enter

Add a comment
Know the answer?
Add Answer to:
Write a main function that gets a number, which represents the height and a character/symbol and...
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 function draw_T in functions.py, which receives three parameters: width, height and symbol. The first...

    Write a function draw_T in functions.py, which receives three parameters: width, height and symbol. The first two parameters are assumed to be integers and the third is a single character string. You don’t need to validate the type of the given parameters. The function returns no values. The function uses the given parameters to draw a T shape, such that the parameter width controls the upper bar, and height controls the middle vertical bar. The parameter symbol, controls which symbol...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • Using Python Please Question 1: Pine Tree Write a program that, prints a 'pine tree' consisting...

    Using Python Please Question 1: Pine Tree Write a program that, prints a 'pine tree' consisting of triangles of increasing sizes, filled with a character (' oror '$' etc). Your program should consist of three functions: 1. A function print_shifted_triangle (n, m, symbol). It prints an n-line triangle, filled with symbol characters, shifted m spaces from the left margin. For example, if we call print_shifted_triangle (3, 4, +"), the expected output is: +++ Left margin +++++ 4 spaces 2. A...

  • ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the...

    ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the file is directly executed Hint: def main(): pass if __name__ == '__main__': main() 2. Your programs will use a file called scores.txt to store a bunch of user-provided numbers. These can be int or float but their values must be between 0 and 100. Inside the main function, display the current list of numbers to the user and ask if they want to update...

  • in Java This program will output a right triangle based on user specified height triangleHeight and...

    in Java This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a character. Modify the given program to output a right triangle that instead uses the user-specified trianglechar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or* Each subsequent line will...

  • write a function which takes a string argument and a character argument. It should return a...

    write a function which takes a string argument and a character argument. It should return a truth value (int 0 or 1), 0 if the string does not contain the character, and 1 if the string does contain the character. Do not use a built-in library for this. Again, call this function and its variables whatever you deem appropriate. The main function of the program should accept a single character followed by Enter. Then, it will read lines until the...

  • I need to write a class in C++. I need to make a class that uses...

    I need to write a class in C++. I need to make a class that uses measurements of a triangle and outputs its area. It needs to have the following things. variables the hold the base and height, and those should be doubles for precision. Member functions to get and set the variables from part one and that check to ensure the values entered are greater than zero. If the values are incorrect, the function must prompt the user for...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • C++ ONLY THANKS! USE VISUAL STUDIO COMPILER ONLY! Part 1: Exercise 1: Problem description Write a...

    C++ ONLY THANKS! USE VISUAL STUDIO COMPILER ONLY! Part 1: Exercise 1: Problem description Write a three function program (your main function and two other functions). The main function of the program should create an array that can store 10 integers. The main function will then pass the array to a second function that gets the integers from the user and stores them in the array. Then your main will call a third function that displays the elements in the...

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