New to programming

I just started this mini text-adventure game...... Can you help me with this?

How can I make my last if() function give me 2 separate answers for what I input with my scanf() function (for "Yes" or "No")?

Note that i just started programming yesterday and i got a lot of tutorials at my hand and I really want to learn a lot. Thanks! (I am from Romania btw...)

http://imgur.com/a/vI9UF



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
#include<stdio.h>

main()
{
	/*daclaring variables as strings */
     char surname[30], name[30];
    char decision_1[10];
  
  /* Hello message fallowed by first question*/
    printf("Hey! \n\n");
	printf("What is you're full name'? \n\n");
	
	 /*Here someone can input they're name and then i play around with that. (I will use those later)*/
    scanf("%s%s", &surname,name);
    printf("\n");
    printf("%s %s? Thats how they call u? Aha..... \n\n", surname, name);
   
   /*Here starts the problem*/
    printf("Want to play a game? \n\n");
 	scanf("%s", decision_1);
 
 /*How can I make the above scanf() be followed by the if function give me two answers*/

 {
 if (decision_1 == "Yes") printf("\nCool!");
else  printf("\nNasty!");
}



Last edited on
I'll recommend you to use std::string (c++)
1
2
3
4
5
6
7
8
9
10
#include <string>

int main(){
   std::string surname, name, decision_1;
   //scanf()
   std::cin >> surname >> name;
   //...
   if (decision_1 == "Yes")
   //...
}


as an alternative, to compare c-strings, use `strcmp()'
if (strcmp(decision_1, "Yes")==0)
1
2
3
4
if (stricmp(decision_1, "Yes") == 0) 
   printf("\nCool!");
else if (stricmp(decision_1, "No") == 0)
   printf("\nNasty!");


You need to include <string.h>

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rtref/stricmp.htm
Thanks! It worked!

:D
Topic archived. No new replies allowed.