Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello again! Still having just a few issues with my code. I will post my solution below and explain what my issues are with it

Hello again! Still having just a few issues with my code. I will post my solution below and explain what my issues are with it exactly.

ACTUAL ISSUES

a.) The triangle function prints fine and does what it needs to do, but it adds extra letters. I wanted to make it to print according to the length of my entered string, but I am unsure of how to do this. I had to learn how to do the triangle function on my own and did it exactly how I saw it, but i am unsure if I am on the right track with it.

b.) my do/while loop won't work exactly. I am trying to wait for the user's response on the last question of whether they want to enter another string or not before proceeding with looping again or exiting, but I am unsure if I constructed this correctly.

Overall, I think my code works 80% so please just let me know what I am doing wrong and please debug based off of my solution. Thank you!

My solution:

#include #include #include #include #include

#define PAUSE system("pause") #define MAX 100

void inReverse(char userStr[]); void inVertical(char userStr[]); void inTri(char userStr[]);

int main(){ char choice; char userStr[MAX] = ""; int i; do{ printf(" Please enter string: "); scanf ("%s", userStr); printf("The string you entered is below: "); printf("Forward: %s", userStr);

printf(" Backwards: "); inReverse(userStr); printf(" Vertical:" ); inVertical(userStr); printf(" Triangle: "); inTri(userStr); printf(" "); int length = strlen(userStr); printf(" Just so you know, the length of your string was: %d", length); printf(" Would you like to enter another string? y or n?: "); scanf("%c", &choice); if (choice == "y"){ choice = 1; } else { choice = 0; printf("Thank you for using my program."); } } while(choice == 1); return 0; }

void inReverse(char userStr[]){ int length = strlen(userStr); int i; for (i = strlen(userStr)-1; i >= 0; i--){ printf("%c", userStr[i]); } }

void inVertical(char userStr[]){ int i; int length= strlen(userStr); for (i = 0; i < strlen(userStr); i++){ printf(" %c ", userStr[i]); } }

void inTri(char userStr[]){ int i; int j; for ( i = 0; i < strlen(userStr); i++) { for (int j = i; j < strlen(userStr); j--) printf("%c ", userStr[j]); printf(" "); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions