用于打印工作人员名称的If语句
If statement to print worker name
我无法获得预期结果,我希望我的程序能显示出来,有人能帮我吗?该程序将打印结构中列出的工人名称,如果你不输入任何这些名称,我应该打印的工人名称不存在。有人能告诉我使用的代码/语法吗
这是我的
#include <stdio.h>
#include <conio.h>
#include <string.h>
//Program Purpose: To accept a specific set of worker names and worker id number and accept the time they came to work and determine if they were early or late for the day.`
struct workers {
char worker_name[10];
int worker_id;
} workers;
int main ()
{
struct workers worker1;
struct workers worker2;
strcpy (worker1.worker_name, "sean");
worker1.worker_Id = 1234;
strcpy (worker2.worker_name,"tajae");
worker2.worker_Id = 7890;
char worker_name [30];
int Worker_Id;
float Time_Arrived;
float Minutes_Late;
float Extra_Minutes;
float Minutes_Early;
float lunch_time;
float Departure;
printf("******************Produce Pro Time Management System********************nn");
printf("Good morning. Welcome to Produce Pro, Hope you had a good nights rest and ready to have a successful day at work today.nn");
printf("Please follow the instruction and answer with the required detailsn");
printf("Note brief: All time are in army hoursnn");
printf("Enter your Worker Namen");
scanf("%S",&worker_name[30]);
if (worker_name= worker1,worker2) // this is the error in the program//
{
printf(&worker_name[30]);
}
else
{
printf ("Worker Name doesn't exist");
}
}
当我更改if语句并放入时
if (worker_name == worker1.worker_name || worker_name == worker2.worker_name)
{
printf("Welcome %sn",worker_name);
}
else printf ("Worker Name doesn't existn");
worker不知道我得到的是什么
如果只检查名称,就不需要在If Condition中指定Struct成员吗?请参见下文。
if (Worker_name == worker1.Worker_name || Worker_name == worker2.Worker_name)
{
printf("Welcome %sn",Worker_name);
}
或
if (strcmp(Worker_name,worker1.Worker_name) != 0 || strcmp(Worker_name,worker2.Worker_name) != 0)
{
printf("Welcome %sn",Worker_name);
}
你应该看看这篇文章,它的答案完全相同:
C: 我该如何编写一个搜索函数来在结构数组中查找匹配项,并返回(打印)它匹配的整个结构?
在C中,可以使用strcmp
以字典方式比较两个以null结尾的(!)字节字符串:
int err = strcmp(worker1,worker2);
if( err == 0))
printf("ok,equaln");
else if(err < 0)
printf("[%s] precedes [%s]n",worker1,worker2);
else if(err > 0)
printf("[%s] follows [%s]n",worker1,worker2);
我认为您需要这样修改scanf和printf语句:
scanf("%s",&Worker_name); //small letter 's'
或者可以是
scanf("%s",Worker_name);
和
printf("%s",Worker_name);
希望这能奏效。。
相关文章:
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- If语句在c++中被忽略
- 比较if语句中的数组值和int值
- 以在Qt中的IF语句中设置时间延迟
- Craps游戏问题,忽略if语句
- c++:定义if语句中的模板
- C++嵌套的 If 语句中,它无法按预期工作
- 如果条件不相关,我应该更喜欢两个 if 语句而不是 if-else 语句吗?
- 需要有关此 if 语句的帮助
- 转换器练习:跳过 if 语句和 if 语句
- 避免在 C++ 中的 if 语句中递增
- 如果仍然不满足要求,如何使 if 语句重复?
- do while 循环中的 if 语句以 yes 或 no 结尾
- 为什么在此C++代码中触发此 if 语句?
- 如何基于平台在制作文件中制作if语句?
- 在 if 语句中使用 GetKeyState 时,它会跳过条件
- C++ If 语句,从其他语句重复