我对C有些问题。请帮助我。我是非常新的C.
我收到了这个错误:
d:\亚纳\ mini.o:mini.c ||未定义的参考`determine_price'|
d:\亚纳\ mini.o:mini.c ||未定义的引用`calc'|
d:\亚纳\ mini.o:mini.c ||对'print_result'|
的未定义引用|| ===构建完成:3个错误,0个警告(0分7秒)=== |
#include<stdio.h>
#include<string.h>
#include <math.h>
void menu();
float determine_price(int);
float calc(float,int);
void print_result(float);
int main()
{
char selection;
int qty,quantity;
float price,pay,item_price,payment;
char set;
printf("**************************\n");
printf("|AZRI & YANA'S CAKE HOUSE|\n");
printf("**************************\n");
printf("\n");
printf("***************************\n");
printf("|1 CUP-------------RM3.50 |\n");
printf("|SET A(3 CUPS)-----RM10.00|\n");
printf("|SET B(6 CUPS)-----RM20.00|\n");
printf("|SET C(12 CUPS)----RM38.00|\n");
printf("***************************\n");
printf("\n");
printf("enter Set and quantity:\n");
scanf("%c %d",&selection,&qty);
price=determine_price(set);
pay= calc(price,qty);
print_result(pay);
return 0;
}
void menu()
{
printf("1 cup = RM3.50\n");
printf("Set A = RM10.00\n");
printf("Set B = RM20.00\n");
printf("Set C = RM38.00\n");
}
float determine_price(int item_code)
{
float set;
if(selection=='1')
printf("1 cup = RM3.50\n");
else if(selection=='A')
printf("Set A = RM10.00\n");
else if(selection=='B')
printf("Set B = RM20.00\n");
else if(selection=='C')
printf("Set C = RM38.00\n");
else
printf("set not available\n");
return(set);
}
float calc(float item_pricing,int quantity)
{
float answer;
answer = item_price*quantity;
return(answer);
}
void print_result(float payment)
{
printf("total cost = %4.2f",payment);
}
我该做什么来调用函数?我需要调用function()还是我的语法错误?
经过大家的帮助修改后,我做了一点编辑..编辑:
现在,我收到了新的错误......
D:\ yana \ mini.c ||在函数'determine_price'中:|
D:\ yana \ mini.c | 54 |错误:'选择'未声明(首次使用此功能)|
D:\ yana \ mini.c | 54 |注意:每个未声明的标识符仅针对它出现的每个函数报告一次|
D:\ yana \ mini.c ||在函数'calc'中:|
D:\ yana \ mini.c | 70 |错误:'item_price'未声明(首次使用此功能)|
|| ===构建完成:2个错误,0个警告(0分0秒)=== |
编辑编号2;
编辑编号2;
我发现了几个错误,感谢所有回答我问题的人..现在,我的新代码...我试着让它成为clrscreen,然而,它不会工作... caN有人帮助我吗?
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
void menu();
int repeat();
float determine_price(char);
float calc(float,int);
void print_result(float);
int main()
{
char selection;
int qty,quantity,choice;
float price,pay,item_price,payment;
//char set;
while(choice!='2'){
menu();
printf("enter Set and quantity:\n");
scanf("%c %d",&selection,&qty);
price=determine_price(selection);
pay= calc(price,qty);
print_result(pay);
choice = repeat();
}
return 0;
}
void menu()
{
printf("**************************\n");
printf("|AZRI & YANA'S CAKE HOUSE|\n");
printf("**************************\n");
printf("\n");
printf("***************************\n");
printf("|1 CUP-------------RM3.50 |\n");
printf("|SET A(3 CUPS)-----RM10.00|\n");
printf("|SET B(6 CUPS)-----RM20.00|\n");
printf("|SET C(12 CUPS)----RM38.00|\n");
printf("***************************\n");
printf("\n");
}
void clr(){
system("cls");
}
int repeat(){
int choice;
printf("\n\n\n\n");
printf("Press\n[1] to return to menu\n[2] to end system\n");
scanf("%d",&choice);
if(choice=='1'){
clr();
}
return choice;
}
float determine_price(char selection){
float setprice;
if(selection=='1'){
printf("1 cup = RM3.50\n");
setprice=3.50;
}
else if(selection=='A'){
printf("Set A = RM10.00\n");
setprice=10.00;
}
else if(selection=='B'){
printf("Set B = RM20.00\n");
setprice=20.00;
}
else if(selection=='C'){
printf("Set C = RM38.00\n");
setprice=38.00;
}
else
printf("set not available\n");
return(setprice);
}
float calc(float item_pricing,int quantity){
float answer;
answer = item_pricing*quantity;
return(answer);
}
void print_result(float payment){
printf("total cost = RM%4.2f",payment);
}
答案 0 :(得分:1)
你的代码是正确的,但你错过了}来关闭你的主要功能。
您必须从主函数中声明函数的规范。
es:
/* Forward declarations */
void a();
float b();
/* Main */
int main() {
...
}
/* Function's specifications */
void a() {
...
}
float b() {
...
}