[英]My input is not showing in c++ at end of program
伙计们,我制作了这个程序。 它按预期工作,但在我的程序结束时它没有显示我的 num 变量输入。 请帮忙。 这是代码:
#include<stdio.h>
int main(){
int f;
int num;
printf("WELCOME TO THE GAME\n\n");
printf("enter F for starting the game\n");
scanf("%d\n\n",&f);
if(f==0){
printf("Ques 01: you are exhausted because your week was endless and less than great.\n");
printf("How are you going to spend your weekend?");
}
printf("\n\n");
printf("Option 01: I'll call my friend to ask about their plans. I heard that a new restaurant opened/ a nice comedy is playing in the cinemas / there are big discounts at the paintball club. ");
printf("\n\n");
printf("option 02: I'll switch on the Don't disturb mode on my phone and stay at home.\n");
printf("I'll watch a new episode of my favorite TV show, do a puzzle, and take a long bath with a book.");
printf("\n\n");
scanf("%d", &num);
}
您需要通过执行以下操作在最后打印出来:
scanf("%s", &num);
printf("num is, ", num);
确保你放了&
符号,它应该可以工作......确保你使用的是正确的编译器,并且在#include <stdio.h>
之间有一个空格,这样你的代码就不会显得混乱。
真正的问题是如果您正在寻找“f”的用户输入,则将if(f==0)
放在哪里,然后将其设置为if(f == "f")
以便您可以使用“f”而不是“ 0”。 使用string f;
或char f
而不是int
。 如果您使用char
,请确保scanf
的格式应如下所示: scanf("%s", &f);
祝你今天过得愉快!
当你输入你的角色时,会发生两件事:
printf("Value of num: %d\n", (int)num);
它将打印出num的值为10,这是ASCII表中'new line'字符的值。 正确的方法(我猜你打算这样做)是:
#include<stdio.h>
int main(){
char f;
int num;
printf("WELCOME TO THE GAME\n\n");
printf("enter F for starting the game\n");
scanf("%c",&f);
if(f=='F'){
printf("Ques 01: you are exhausted because your week was endless and less than great.\n");
printf("How are you going to spend your weekend?");
}
printf("\n\n");
printf("Option 01: I'll call my friend to ask about their plans. I heard that a new restaurant opened/ a nice comedy is playing in the cinemas / there are big discounts at the paintball club. ");
printf("\n\n");
printf("option 02: I'll switch on the Don't disturb mode on my phone and stay at home.\n");
printf("I'll watch a new episode of my favorite TV show, do a puzzle, and take a long bath with a book.");
printf("\n\n");
printf("Enter a number....:");
scanf("%d", &num);
printf("You just enter number %d\n", num);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.