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 MAX_DIMENSION = 25;
void printLine(int length){
scanf("%d", &length);
for(int i=0; i<length; i++){
if(length<0 && length>25){
printf("That input is invalid.");
else{
printf("*");
}
}
}
}
void printTriangle(int baseLength){
scanf("%d", &baseLength);
for(int i=0; i<baselength; i++){
if(length<3 && length>25){
printf("That input is invalid.");
else{
printf("*");
}
}
}
}
void printRectangle(int width, int height){
scanf("%d %d", &width, &height);
for(int i=0; i<width; i++){
for(int j=0; j<height; j++){
if((width<2 && width>25) && (height<2 && height>25){
printf("That input is invalid.");
else{
printf("*");
}
}
}
}
}
int main() {
char option;
printf("Which shape (L-line, T-triangle, R-rectangle): ");
scanf("%c", &option);
option = toupper(option);
printf("\n");
switch (option) {
case 'L' || case 'l':
printf("Enter an Integer length between 1 and 25");
printLine();
break;
case 'T' || case 't':
printf("Enter an Integer base length between 3 and 25");
printTriangle();
break;
case 'R'|| case 'r':
printf("Enter an Integer width and height between 2 and 25");
printRectangle();
break;
default:
break;
}
return 0;
}
Given, Asked to write a C refactor code which will print line, triangle and rectangle with char "*" with initial criteria for each using switch menu.
Code:
#include <stdio.h>
#include <ctype.h>
const int MAX_DIMENSION = 25;
void printLine()
{
int length;
scanf("%d", &length);
for(int i=0; i<length; i++)
{
if(length<0 || length>25)
{
printf("That input is invalid.");
break;
}
else
printf("*");
}
}
void printTriangle()
{
int baseLength;
printf("Enter an integer base length between 3 and 25: ");
scanf("%d",&baseLength);
if(baseLength<3 || baseLength>25)
{
printf("That input is invalid.\n");
}
else
{
for(int i=0; i<baseLength; i++)
{
for(int j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
}
void printRectangle()
{
int width, height;
scanf("%d %d", &width, &height);
if((width<2 || width>25) || (height<2 ||
height>25))
{
printf("That input is invalid.\n");
}
else
{
for(int i=0; i<width; i++)
{
for(int j=0; j<height; j++)
{
printf("*");
}
printf("\n");
}
}
}
int main() {
char option;
printf("Which shape (L-line, T-triangle, R-rectangle): ");
scanf("%c", &option);
option = toupper(option);
printf("\n");
switch (option) {
case 'L':
printf("Enter an Integer length between 1 and 25: ");
printLine();
break;
case 'T':
printf("Enter an Integer base length between 3 and 25: ");
printTriangle();
break;
case 'R':
printf("Enter an Integer width and height between 2 and 25:
");
printRectangle();
break;
default:
break;
}
return 0;
}
Output:


Please let me know in the comments if you need more help in this.
I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle):...
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...
i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...
So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
I'm having trouble getting this program to compile and run. It is in C++ Language and being run with CodeBlocks. Problem Statement: create and manage a linked list. Program will loop displaying a menu of user operations concerning the management of a linked list. Included will be: H create link at head R remove link at head T create link at tail K remove link at tail I remove link at ID S search...
I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...
i'm having trouble making an else statement that will allow the program to add and output the average the valid numbers inputed into the program. Here's my output: Enter Score 1:36 Enter Score 2:-1 Invalid Input Enter Score 2:89.5 Enter Score 3:42 Enter Score 4:66.3 Enter Score 5:93 You entered: 36.000000, 89.500000, 42.000000, 66.300000, 93.000000 Total Score: 362.800000 Average Score: 72.560000 Max Score: 93.000000 Min Score: 36.000000 Here's my code: #include <stdio.h> int main(void) { double score[5]; double min; double...
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...
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...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...