Please help me!

My code is supposed to prompt the user for how they are feeling.
If they say "good", "great" or "well" it is supposed to respond with "Super! Tell me more."
If the user says "bad", "sad", or "not", it is supposed to respond "Sorry to hear that. Tell me more."
If they say anything else it should say "I see. Tell me more."
It is then just supposed to loop asking that question forever.
I think I went about making this code in a very roundabout way with too many variables and condition statements because I am very new to coding. However, I still don't know why it isn't working.
Please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <string.h>
/* the code starts here */
int main(void)
{
    char goodresponse1[] = "good";
    char goodresponse2[] = "great";
    char goodresponse3[] = "well";
    char badresponse1[]= "bad";
    char badresponse2[]= "sad";
    char badresponse3[]= "not";
    
    char response[100];
    
    while(1){
        
        printf("How are you today?\n");
        gets(response);
        
        if (strcmp(response, badresponse1))
        {
            printf("Super! \n Tell me more.\n");
        }
        else if (strcmp(response, badresponse2))
        {
            printf("Super! \n Tell me more.\n");
        }
        else if (strcmp(response, badresponse3))
        {
            printf("Super! \n Tell me more.\n");
        }
        else if (strcmp(response, goodresponse1))
        {
            printf("I'm sorry to hear that. \n Tell me more.\n");
            
        }
        else if (strcmp(response, goodresponse2))
        {
            printf("I'm sorry to hear that. \n Tell me more.\n");
            
        }
        else if (strcmp(response, goodresponse3))
        {
            printf("I'm sorry to hear that. \n Tell me more.\n");
            
        }
        else
        {
            printf("I see. \n Tell me more. \n");
            
        }
    }
    
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <string.h>
/* the code starts here */
int main(void)
{
    char goodresponse1[] = "good";
    char goodresponse2[] = "great";
    char goodresponse3[] = "well";
    char badresponse1[]= "bad";
    char badresponse2[]= "sad";
    char badresponse3[]= "not";
    
    char response[100];
    
    while(1)
	{
        
        printf("How are you today?\n");
        gets(response);
        
        if (strcmp(response, badresponse1) == 0)
        {
			printf("I'm sorry to hear that. \n Tell me more.\n");
        }
        else if (strcmp(response, badresponse2) == 0)
        {
            printf("I'm sorry to hear that. \n Tell me more.\n");
        }
        else if (strcmp(response, badresponse3) == 0)
        {
            printf("I'm sorry to hear that. \n Tell me more.\n");
        }
        else if (strcmp(response, goodresponse1) == 0)
        {
            printf("Super! \n Tell me more.\n");
            
        }
        else if (strcmp(response, goodresponse2) == 0)
        {
			printf("Super! \n Tell me more.\n");           
        }
        else if (strcmp(response, goodresponse3) == 0)
        {
            printf("Super! \n Tell me more.\n");
            
        }
        else
        {
            printf("I see. \n Tell me more. \n");
            
        }
    }
    
}


strcmp returns zero if the strings are equal
http://www.cplusplus.com/reference/cstring/strcmp/
Last edited on
Topic archived. No new replies allowed.