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. Can’t 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 <stdio.h>
#include <stdlib.h>
#include <time.h>
void diamond(int size, char symbol)
{
printf("Make a diamond that is %d high\n", 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\n", size);
int column, row;
for(row = 0; row < size; row+= 1)
{
printn(size, symbol);
printf("\n");
}
}
void triangle (int size, char symbol)
{
printf("Make a triangle that is %d high\n", 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("\n");
}
}
int main()
{
while(1)
{
printf("Please choose one of the
following:\n"
"S -- print a
square\n"
"D -- print a diamond\n"
"T -- print a triangle\n"
"Q -- and quit: ");
char which[2];
scanf("%s", which);
//printf("The user typed %s\n",
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\n",
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\n");
}
//To do: be sure size is in
range
}
}
Note: Could you plz go this code and let me know if
u need any changes in this.Thank You
_________________
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void diamond(int size, char symbol)
{
printf("Make a diamond that is %d high ", size);
int spc=1,num,h,m;
if (size % 2 == 0)
{
printf("Invalid Number.Rows Must be Odd Number ");
}
else
{
spc = num - 1;
// These two loops prints diamond shape
for (h = 1; h < num - 1; h++)
{
for (m = 1; m <= spc; m++)
printf(" ");
spc--;
for (m = 1; m <= 2 * h - 1; m++)
printf("*");
printf(" ");
printf(" ");
}
spc = 1;
for (h = 1; h <= num - 1; h++)
{
for (m = 1; m <= spc + 2; m++)
printf(" ");
spc++;
for (m = 1; m <= 2 * (num - h - 2) - 1; m++)
printf("*");
printf(" ");
printf(" ");
}
}
}
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(" ");
}
}
// This function will display the triangle
void displayTriangle(int size, char symbol)
{
int i,j;
// Getting the rows value entered by the user
if (size % 2 == 0)
{
printf("Invalid Number.Rows Must be Odd Number ");
}
else
{
for (i = 0; i <= size; i++)
{
for (j = 0; j < size; j++)
{
if (j > size - i - 1)
{
printf("%c",symbol);
printf(" ");
}
else
{
printf(" ");
}
}
printf(" ");
}
}
}
int main()
{
char choice,symbol;
while(1)
{
printf(" Please choose one of the following: "
"S -- print a square "
"D -- print a diamond "
"T -- print a triangle "
"Q -- and quit ");
printf(" Enter Choice :");
scanf(" %c",&choice);
if (choice == 'Q' || choice == 'q')
{
break;
}
int size;
do
{
printf("What size? ");
scanf("%d",&size);
}while(size<7 || size>17);
printf("What symbol? ");
scanf(" %c",&symbol);
printf("The user typed %c ", symbol);
//printf("The user typed %s ", which);
if(choice == 'S' ||choice == 's')
{
square(size,symbol);
} else if (choice == 'D'||choice == 'd')
{
diamond(size, symbol);
}
else if (choice == 'T'||choice == 't')
{
displayTriangle(size,symbol);
}
else {
printf("Please make a valid choice ");
}
//To do: be sure size is in range
}
}
__________________________
Output:


_______________Could you plz rate me well.Thank You
Write a C program that does the following: Displays a menu (similar to what you see...
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...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...
I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...
IN JAVA Overview In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide the user to decide between different forms...
I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...
In C programming language: 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 *....
I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...