#include<stdio.h> int main() { int price = 0; printf("请输入金额(元)"); scanf_s ("%d,&prtice" ); int charge = 100 - price; printf("找您%d元\n", charge); return 0; }
时间: 2024-03-22 19:38:35 浏览: 15
这是一个简单的 C 语言程序,实现了一个找零的功能。用户输入商品的价格,程序会自动计算出需要找给用户的零钱。
但是,程序中有一个小错误,就是 scanf_s 函数的参数写错了,应该是 "%d" 而不是 "%d,&price",应该改为:
```
scanf_s("%d", &price);
```
这样程序才能正确读取用户输入的价格。
相关问题
#include <stdio.h> int main() { int price = 0; printf("请输入金额(元):"); scanf("%d", &price); int change = 100 - price; printf("找您%d元。\n", change); return 0; } 这个程序没法运行
这个程序应该可以运行,但是需要注意以下几个问题:
1. 缺少头文件:程序中使用了printf和scanf函数,需要包含头文件stdio.h。
2. 缺少main函数:程序中缺少主函数main,在程序中加入main函数。
3. 缺少输入金额的提示信息:程序中缺少提示用户输入金额的信息,需要使用printf函数输出提示。
下面是修改后的程序:
```
#include <stdio.h>
int main() {
int price = 0;
printf("请输入金额(元):");
scanf("%d", &price);
int change = 100 - price;
printf("找您%d元。\n", change);
return 0;
}
```
这个程序可以正常运行,并且会提示用户输入金额,计算出需要找回多少钱。需要注意的是,这个程序没有进行错误处理,如果用户输入的金额大于100元,程序会输出错误的找回金额。在实际应用中,需要对这些情况进行处理。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include "添加药品.cpp" struct medicine { char name[20]; char number[50]; char price[50]; char type[10]; char inventory[50]; char brand[20]; char time[60]; char remark[30]; }medicines[100]; int num; int main(void) { int selectnum;add_medicine(); }int add_medicine() { printf("输入要保存的药品信息\n"); printf("输入药品名称\n"); scanf("%s",medicines[num].name); printf("输入药品编号\n"); scanf("%s",medicines[num].number); printf("输入药品单价\n"); return 0; } 帮我将这串代码分成两个cpp文件,一个主文件,一个子文件
主文件(main.cpp):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "medicine.h"
struct medicine medicines[100];
int num;
int main(void) {
int selectnum;
add_medicine();
return 0;
}
子文件(medicine.cpp):
#include "medicine.h"
#include <stdio.h>
int add_medicine() {
printf("输入要保存的药品信息\n");
printf("输入药品名称\n");
scanf("%s",medicines[num].name);
printf("输入药品编号\n");
scanf("%s",medicines[num].number);
printf("输入药品单价\n");
return 0;
}
头文件(medicine.h):
#ifndef MEDICINE_H
#define MEDICINE_H
struct medicine {
char name[20];
char number[50];
char price[50];
char type[10];
char inventory[50];
char brand[20];
char time[60];
char remark[30];
};
int add_medicine();
#endif