#include <stdio.h> int main() { int price = 0; printf("请输入金额(元):"); scanf("%d", &price); int change = 100 - price; printf("找您%d元。\n", change); return 0; } 这个程序没法运行
时间: 2024-03-17 22:44:42 浏览: 23
这个程序应该可以运行,但是需要注意以下几个问题:
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> int main() { int price = 0; printf("请输入金额(元)"); scanf_s ("%d,&prtice" ); int charge = 100 - price; printf("找您%d元\n", charge); return 0; }
这是一个简单的 C 语言程序,实现了一个找零的功能。用户输入一个金额,程序会自动计算出找回给用户的钱数。不过有一个小问题,代码中的 scanf_s 函数的参数书写有误,应该是 scanf_s("%d", &price)。正确的代码如下:
```c
#include <stdio.h>
int main() {
int price = 0;
printf("请输入金额(元)");
scanf_s("%d", &price);
int charge = 100 - price;
printf("找您%d元\n", charge);
return 0;
}
```
当用户输入金额后,程序会计算出找回的钱数并输出。这个程序比较简单,但是也是 C 语言初学者的一个练手好题。
#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
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)