- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好的,我现在尝试使用 check_status() 下面的函数检查代码。
它们在代码中没有错误,但我认为我搞砸了逻辑。当它运行时我想做的是放在 S 中并打印“CORRECT ANSWER.S”
现在,当您输入 FEFWRGV 或不是 S、SH、MJ、MS 的内容时,代码可以正常工作并打印出错误消息。然而!当你输入 SSDFIEWF 或类似的东西时,它会显示“CORRECT ANSWER.S”
我检查是否输入了 S 的方法是如果(状态[0] == 'S')
有没有办法让我写出如下代码:如果(状态[0] == 'S' && 状态[1] == 无效)
因为我知道我正在做的是检查 status[0],然后我想确保 status[1] 没有被使用。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <cstdio>
//functions called
float wages_loop();
float other_loop();
float interest_loop();
void check_status();
//start main
int main(void)
{
char status[10], another[10];
char buffer[80];
float wages, other_income, interest, dividends, test;
int dependents;
int single_acc = 0, mj_acc = 0, ms_acc = 0, sh_acc = 0;
printf("Would you like to start: ");
gets_s(another);
if (another[0] != 'y' && another[0] != 'n')
{
while (another[0] != 'y' && another[0] != 'n')
{
printf("\n\n INCORRCT ANSWER. \n\n");
printf("\n Would you like to start. (y or n)");
gets_s(another);
}
}
while (another[0] == 'y')
{
check_status();
interest = 0;
printf("\n\n\t\t Your interest is: %.2f \n", interest);
system("pause");
printf("Would you like anoter: ");
gets_s(another);
if (another[0] != 'y' && another[0] != 'n')
{
while (another[0] != 'y' && another[0] != 'n')
{
printf("\n\n INCORRCT ANSWER. \n\n");
printf("\n Would you like anoter. (y or n)");
gets_s(another);
}
}
} //end loop
printf("\n\n\t\t\t Number of Singles filleing: %i \n", single_acc);
return 0;
}//end main
void check_status()
{
char status[10];
int check = 0;
while (check != 1)
{
printf("What is your Status: ");
gets_s(status);
if (status[0] == 'S' && status[1] == 'H')
{
printf("\n\n CORRECT ANSWER. SH \n\n");
check = 1;
}
else if (status[0] == 'S')
{
printf("\n\n CORRECT ANSWER. S \n\n");
check = 1;
}
else if (status[0] == 'M' && status[1] == 'J')
{
printf("\n\n CORRECT ANSWER. MJ \n\n");
check = 1;
}
else if (status[0] == 'M' && status[1] == 'S')
{
printf("\n\n CORRECT ANSWER. MS \n\n");
check = 1;
}
else
{
printf("\n\n INCORRECT ANSWER. noting \n\n");
}
}
}
最佳答案
Is there a way i can write a code like: if (status[0] == 'S' && status1 == void)
您快完成了。 C-“string”-终止符不是 void
而是 '\0'
。
因此,要测试“字符串”是否在第 1 个st 字符之后结束,即 status[0]
,请执行以下操作:
if (status[0] == 'S' && status[1] == '\0')
顺便说一句:要声明一个不带任何参数的函数,请使用 void
,如下所示:
check_status(void);
作为Joachim Pileborg已经对您的问题发表了评论,您使用的 gets_s()
不正确。 gets_s()
takes two parameters .
编译器应该警告您缺少第二个参数。
认真对待此类警告是个好主意。
关于c++ - if else 字符逻辑有缺陷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21872951/
我想捕捉发送到我的窗口的按键以存储每个键的状态,并区分键的左右实例,如 WM_LCONTROL 和 WM_RCONTROL. 因为 WM_KEYUP/DOWN 不提供此功能,所以我转向原始输入,我需要
我有以下代码: Area here jQuery: $('#area').on('mouseenter', function(event){ $('#area').addC
这个问题在这里已经有了答案: Why does a RegExp with global flag give wrong results? (7 个答案) 关闭 7 个月前。 我向你保证我没有说谎。
我想知道以下问题的答案。 1) 如果我尝试使用 AVAudioSession 播放音频,而 iphone 扬声器有故障/有缺陷/不工作,会发生什么情况? 2) 有什么方法可以通过程序检查扬声器是正常工
我是一名优秀的程序员,十分优秀!