题目:声明两个int型变量或赋值,判断两数之和,,如果大于等于50,输出hello,world
运行输入30 50,再按一次回车会直接跳出去,不会显示hello,world
#include<iostream>
using namespace std;
int main()
{
int n = 0, i = 0;
printf("请输入两个数:");
scanf_s("%d/t%d", n, i);
if ( n + i >= 50)
printf("/nhello,world");
getchar();
getchar();
}
I actually saw Chinese people here, let me answer.
When you use scanf_s to enter variable values, n and i are preceded by & because it requires the address of the variable. This is the requirement of this C function
Also, I don't know why you have to add /t between your two %ds, you need to remove them. Otherwise, it cannot be output normally, or you can change it to \t. Also, in your printf, you may want to use /n to wrap a line, but use \n instead of /n, and the last two getchar() may be used to prevent the program from jumping directly after running out?
If you want the program to pause, use system("pause");
Some formatting & indentation would not hurt either
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream>
usingnamespace std;
int main()
{
int n = 0, i = 0;
printf("请输入两个数:");
scanf_s("%d/t%d", n, i);
if (n + i >= 50)
printf("/nhello,world");
getchar();
getchar();
}
This is using C I/O functions exclusively, including <iostream> is a bit odd. Odd, not wrong. <stdio.h> or <cstdio> is a more reasonable header to include, whether the code is compiled as C or C++.