填写遗漏的代码 [英] Fill the missing code

查看:91
本文介绍了填写遗漏的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的程序中填写缺少的代码,从标准输入读取员工性别,年龄和工资,并将其打印到标准输出。

Fill in the missing code in the below program to read an employee gender,age and salary from standard input and prints same to the standard output.

#include <stdio.h>
void main() {
    char gender;
    short int age;
    float salary;
    printf("Enter an employee gender (M/F), age, salary : ");
    printf("Employee gender is : \n", );
    printf("Employee age is : \n", );
    printf(Employee salary is : \n", );
}





我的尝试:





What I have tried:

#include <stdio.h>
void main() {
    char gender;
    short int age;
    float salary;
    printf("Enter an employee gender (M/F), age, salary : ");
    scanf("%c, %d, %f", &gender, &age, &salary)
    printf("Employee gender is : %c\n", gender);
    printf("Employee age is : %d\n", age);
    printf(Employee salary is : %f\n", salary);
}

推荐答案

所以,你没有尝试自己解决问题,你毫无疑问,你只是想让我们做你的家庭工作。

家庭工作问题是你在现实生活中必须解决的问题的简化版本,他们的目的是学习和练习

我们不做你的家庭作业。



HomeWork不会测试你乞求别人做你的工作的技巧,它是为了让您思考并帮助您的老师检查您对所学课程的理解以及您应用它们时遇到的问题。

任何失败都会帮助您的老师发现您的弱点并设置补救措施。

您的任何失败都将帮助您了解哪些有效,哪些无效,它被称为'试错'学习ning。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个确切的问题,我们可能会提供帮助。
So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.
We do not do your HomeWork.

HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


只需编译它并检查错误和警告消息。请注意,这些消息会告知您编号检测到问题的行号和列(此处使用GCC作为示例)。



Just compile it and inspect the error and warning messages. Note that the messages inform you about the line number and the column where the compiler detected a problem (here using GCC as example).

test.c:2:6: warning: return type of ‘main’ is not ‘int’

main()应该返回一个int:

main() should return an int:

int main()
{
    /* code goes here*/
    return 0;
}




test.c:7:1: warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘short int *’

你必须使用 h 前缀 short 整数:

You have to use the h prefix for short integers:

//scanf("%c, %d, %f", &gender, &age, &salary)
scanf("%c, %hd, %f", &gender, &age, &salary);




test.c:8:1: error: expected ‘;’ before ‘printf’

在前一行的末尾有一个分号丢失(见上文;我已经在那里添加了分号)。



There is a semicolon missing at the end of the previous line (see above; I have added it there already).

test.c:10:8: error: ‘Employee’ undeclared (first use in this function)
... (more errors on line 10)

该行缺少双重报价:

There is a double quote missing on that line:

//printf(Employee salary is : %f\n", salary);
printf("Employee salary is : %f\n", salary);


这篇关于填写遗漏的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆