问题描述
我对编程非常陌生,在我的课程中,我们学习了 c 语言,因此请怜悯我编写的糟糕代码,并且编译器由于错误而无法运行该程序,因此我很难确定哪里出了问题。回到主要问题我得到未解析的外部符号...在 function_main 中引用,我真的不知道我在哪里搞砸了
#include<stdio.h>
char displayMenu(void);
void ViewBooks();
void SearchBookPrice();
void UpdateBookPrice();
int main()
{
char userchoice;
int bookID[5] = { 200,230,500,540,700 };
char bookTitle[5][50] = { {"Using @R_379_4045@ion Technology 12th Edition" },{ "Beyond HTML" },{"Build Your Own PC"},{"Instant Java Servlets"},{"DIgital Image: A Practical Guide"} };
float bookPrice[5] = { 100.30,50.40,47,83.30,22.90 };
do
{
userchoice = displayMenu();
if (userchoice == 'V')
ViewBooks();
else if (userchoice == 'S')
SearchBookPrice();
else if (userchoice == 'U')
UpdateBookPrice();
} while (userchoice != 'E');
printf("Thank you for using our system. Have a nice day!\n");
return 0;
}
char displayMenu(void)
{
char choice;
printf("*************************************************************************\n");
printf("V:View Books S:Search Book Price U:Update Book Price E:Exit");
printf("*************************************************************************\n");
do
{
printf("Enter your choice: ");
scanf(" %c",&choice);
if (choice != 'V' && choice != 'S' && choice != 'U' && choice != 'E')
printf("Invalid Choice\n");
} while (choice != 'V' && choice != 'S' && choice != 'U' && choice != 'E');
return choice;
}
void ViewBooks(int bookID[],float bookPrice[])
{
printf("%d Using @R_379_4045@ion Technology 12th Edition $%f\n",bookID[0],bookPrice[0]);
printf("%d Beyond HTML $%f\n",bookID[1],bookPrice[1]);
printf("%d Build Your Own PC $%f\n",bookID[2],bookPrice[2]);
printf("%d Instant Java Servlets $%f\n",bookID[3],bookPrice[3]);
printf("%d Digital Image: A Pratical Guide $%f\n",bookID[4],bookPrice[4]);
return;
}
void SearchBookPrice(int bookID[5],char bookTitle[5][50],float bookPrice[5])
{
int idsearch,i= 0,match = -1;
printf("*************************************************************************\n");
printf("Search by book ID\n");
printf("*************************************************************************\n");
printf("Enter book ID: ");
scanf("%d",&idsearch);
while (i<5 && match==-1)
{
if (bookID[i] == idsearch)
match = i;
i++;
}
if (match == -1)
printf("Please refer to the customer service for assitance");
else
{
printf("The book id is : %d\n",&idsearch);
printf("The price of %s is %f",bookTitle[match],bookPrice[match]);
}
return;
}
void UpdateBookPrice(int bookID[5],i = 0,match = -1;
printf("Enter book ID: ");
scanf("%d",&idsearch);
while (i < 5 && match == -1)
{
if (bookID[i] == idsearch)
match = i;
i++;
}
if (match == -1)
printf("The book ID is not found. Please make sure the book ID is correct");
else
{
printf("Current book price is %f\n",bookPrice[match]);
printf("Enter new price for (%d-%s): ",bookID[match],bookTitle[match]);
scanf("%f",&bookPrice[match]);
}
return;
}
解决方法
您的函数声明与函数体不匹配。
这是工作代码。
#include<stdio.h>
char DisplayMenu(void);
void ViewBooks(int bookID[],float bookPrice[]);
void SearchBookPrice(int bookID[5],char bookTitle[5][50],float bookPrice[5]);
void UpdateBookPrice(int bookID[5],float bookPrice[5]);
int main()
{
char userchoice;
int bookID[5] = { 200,230,500,540,700 };
char bookTitle[5][50] = { {"Using Information Technology 12th Edition" },{ "Beyond HTML" },{"Build Your Own PC"},{"Instant Java Servlets"},{"DIgital Image: A Practical Guide"} };
float bookPrice[5] = { 100.30,50.40,47,83.30,22.90 };
do
{
userchoice = DisplayMenu();
if (userchoice == 'V')
ViewBooks(bookID,bookPrice);
else if (userchoice == 'S')
SearchBookPrice(bookID,bookTitle,bookPrice);
else if (userchoice == 'U')
UpdateBookPrice(bookID,bookPrice);
} while (userchoice != 'E');
printf("Thank you for using our system. Have a nice day!\n");
return 0;
}
char DisplayMenu(void)
{
char choice;
printf("*************************************************************************\n");
printf("V:View Books S:Search Book Price U:Update Book Price E:Exit");
printf("*************************************************************************\n");
do
{
printf("Enter your choice: ");
scanf(" %c",&choice);
if (choice != 'V' && choice != 'S' && choice != 'U' && choice != 'E')
printf("Invalid Choice\n");
} while (choice != 'V' && choice != 'S' && choice != 'U' && choice != 'E');
return choice;
}
void ViewBooks(int bookID[],float bookPrice[])
{
printf("%d Using Information Technology 12th Edition $%f\n",bookID[0],bookPrice[0]);
printf("%d Beyond HTML $%f\n",bookID[1],bookPrice[1]);
printf("%d Build Your Own PC $%f\n",bookID[2],bookPrice[2]);
printf("%d Instant Java Servlets $%f\n",bookID[3],bookPrice[3]);
printf("%d Digital Image: A Pratical Guide $%f\n",bookID[4],bookPrice[4]);
return;
}
void SearchBookPrice(int bookID[5],float bookPrice[5])
{
int idsearch,i= 0,match = -1;
printf("*************************************************************************\n");
printf("Search by book ID\n");
printf("*************************************************************************\n");
printf("Enter book ID: ");
scanf("%d",&idsearch);
while (i<5 && match==-1)
{
if (bookID[i] == idsearch)
match = i;
i++;
}
if (match == -1)
printf("Please refer to the customer service for assitance");
else
{
printf("The book id is : %d\n",&idsearch);
printf("The price of %s is %f",bookTitle[match],bookPrice[match]);
}
return;
}
void UpdateBookPrice(int bookID[5],i = 0,match = -1;
printf("Enter book ID: ");
scanf("%d",&idsearch);
while (i < 5 && match == -1)
{
if (bookID[i] == idsearch)
match = i;
i++;
}
if (match == -1)
printf("The book ID is not found. Please make sure the book ID is correct");
else
{
printf("Current book price is %f\n",bookPrice[match]);
printf("Enter new price for (%d-%s): ",bookID[match],bookTitle[match]);
scanf("%f",&bookPrice[match]);
}
return;
}