修正下列代码并完善它 #include<stdio.h> int main(void) { int python,math,english,physical_education,military_theory,philosophy python = 3; math = 4; english = 4; physical_education= 2; military_theory = 2; philosophy = 2; scanf("%d,%d,%d,%d,%d,%d",&python,&math,&english,&physical_education,&military_theory,&philosophy); tuition_per_credit = int(input()); total_credits = (python + math + english + physical_education + military_theory + philosophy); total_tuition = total_credits * tuition_per_credit; living_expenses = float(input()); total_cost = living_expenses * 5 + total_tuition; student_loan = total_cost * 0.6; printf("student_loan "); return 0; }
时间: 2024-03-03 16:52:26 浏览: 127
以下是修正后的代码:
```
#include<stdio.h>
int main(void) {
int python, math, english, physical_education, military_theory, philosophy;
float tuition_per_credit, living_expenses, total_cost, student_loan;
printf("请输入 Python 成绩、数学成绩、英语成绩、体育成绩、军事理论成绩和哲学成绩(以逗号分隔):");
scanf("%d,%d,%d,%d,%d,%d", &python, &math, &english, &physical_education, &military_theory, &philosophy);
printf("请输入每学分的学费:");
scanf("%f", &tuition_per_credit);
int total_credits = python + math + english + physical_education + military_theory + philosophy;
float total_tuition = total_credits * tuition_per_credit;
printf("请输入每月生活费用:");
scanf("%f", &living_expenses);
total_cost = living_expenses * 5 + total_tuition;
student_loan = total_cost * 0.6;
printf("你需要申请 %.2f 元的学生贷款\n", student_loan);
return 0;
}
```
主要修正包括:
1. 添加了变量的声明,包括 `tuition_per_credit`、`living_expenses`、`total_cost` 和 `student_loan`;
2. 修改了 `scanf` 函数中的格式化字符串,使其与输入的变量类型匹配;
3. 添加了用户输入的提示信息;
4. 修改了输出语句,使其输出正确的结果。
阅读全文