Question
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
#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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started