编程知识 cdmana.com

[C language] I want to make an interactive game, like station B. is it done with the select function switch and how to implement it?

The phenomenon and background of the problem

How to make branch code ?
Branch outputs some characters

#include<stdio.h>#define MAXN 100int Count = 0;void select(int option1);int main (void){    int option1;    printf(" In the morning , Paralyzed in the soft bed, you open your eyes , Sitting on his stomach ...... A strange girl ?!!!\n");    printf("[1] Give her a punch \n");    printf("[2] Ask who she is \n");    printf("Please enter your option:");    scanf_s("%d", &option1);    select(option1);    select(option2);    printf("Thank.");    return 0;}void select(int option1){    switch (option1)    {        case 1:            printf("[1] The girl didn't cry , Give me another punch \n");            printf("[2] Forget it , No more fighting , Ask who she is \n");            printf("Please enter your option:");            scanf_s("%d", &option1);            break;        case 2:            printf("BB/n");            printf("Please enter your option:");            scanf_s("%d", &option1);            break;    }}void select(int option2){    switch (option2)    {        case 1:            printf("[1] The girl didn't cry , Give me another punch \n");            printf("[2] Forget it , No more fighting , Ask who she is \n");            printf("Please enter your option:");            scanf_s("%d", &option1);            break;        case 2:            printf("BB/n");            printf("Please enter your option:");            scanf_s("%d", &option1);            break;    }}
Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve



Refer to the answer 1:

Character parameters can also use switch sentence .




Refer to the answer 2:



Refer to the answer 3:

Your mistake ....




Refer to the answer 4:

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/12/202112121746125015.html

Scroll to Top