Question: Write a C program that does the following: Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user

  1. Write a C program that does the following:

    • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the

      user to enter a single character S or D or Q and then prints a shape of Square,Diamond (with selected height and selected symbol), or Quits if user entered Q.Apart from these 2 other shapes, add a new shape of your choice for any related character.

    • Program then prompts the user to enter a number and then prompts to enter a symbol. The allowable range of numbers is [7, 17] which will be used as height of the above shape and any symbol is acceptable.

    • Your program should be case insensitive. Uppercase and lowercase inputs will be considered correct! You must use if-else statements to make appropriate choices in the menu. Cant use switch statement here! Logic to draw the shape can be implemented using any loop statements but you cannot use same loop statement twice.

    • After displaying the shapes, show the menu again automatically. Note: there will be no other way to stop the program until user enters Q.

      Hint: You may want to create separate functions for drawing each shape.

Here is what I have so far, I am struggling with creating a diamond and the allowable range of numbers........

#include #include #include

void diamond(int size, char symbol) { printf("Make a diamond that is %d high ", size);

}

void printn(int n, char symbol) { int i; for(i = 0; i < n; i+= 1){ printf("%c", symbol); } }

void square(int size, char symbol) { printf("Make a square that is %d high ", size);

int column, row; for(row = 0; row < size; row+= 1) { printn(size, symbol);

printf(" "); } }

void triangle (int size, char symbol) { printf("Make a triangle that is %d high ", size);

int row; for(row=0; row < size; row+= 1) { //print leading spaces for this row //prints symbols for this row //print a new line to end the row //size minus row minus 1 printn(size - row - 1, ' '); printn(row * 2 + 1, symbol); printf(" ");

}

} int main() { while(1) { printf("Please choose one of the following: " "S -- print a square " "D -- print a diamond " "T -- print a triangle " "Q -- and quit: ");

char which[2]; scanf("%s", which); //printf("The user typed %s ", which); if (which[0] == 'Q') { break; } printf("What size? "); int size; scanf("%d", &size); printf("What symbol? "); char symbol[2]; scanf("%s", symbol); printf("The user typed %s ", symbol);

if(which[0] == 'S') { square(size, symbol[0]); } else if (which[0] == 'D') { diamond(size, symbol[0]); } else if (which[0] == 'T') {

triangle(size, symbol[0]); } else { printf("Please make a valid choice "); } //To do: be sure size is in range }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!