我目前是 c 的新手,我今天有一个任务要完成。我写了这个作业将近 5 个小时。我一直在谷歌搜索,并阅读stackoverflow。请帮我解决我的代码。我不明白为什么我的“成本”数组没有打印出浮点数。我一直在尝试使用“put()”函数,看看是否可以修复它。它仍然不起作用,因为我认为它只需要字符而不是整数?好吧,我需要帮助。
预期输出是这个链接:https ://imgur.com/N0IZpif
#include <string.h>
#include <stdio.h>
#define cost1 3
#define cost2 2
#define books1 3
#define books2 2
int main()
{
float cis_total= 0;
float math_total = 0;
float total_sales;
float FIN_AID=.20;
const char* cis_books[books1];
cis_books[0] = "Programming 1";
cis_books[1] = "Intro to Networking";
cis_books[2] = "Javascript";
float cis_cost[cost1];
cis_cost[0] = 55.5;
cis_cost[1] = 35.8;
cis_cost[2] = 67.5;
const char* math_books[books2];
math_books[0] = "Calculus";
math_books[1] = "Intro to Geometry";
float math_cost[cost2];
math_cost[0] = 25.5;
math_cost[1] = 54.5;
printf("Welcome to the ECPI Bookstore Reservation System!\n");
printf("\nPlease see your totals below!\n");
printf("\nCIS Book Totals:\n");
for(int i=0;i<cost1;i++)
{
if(i == cost1-1)
puts(cis_books[i]);
else
puts(cis_books[i]);
}
for(int i=0; i <cost1; i++)
{
cis_total +=cis_cost[i];
printf("\nCost of your CIS Books: $%.1f "), cis_cost[i];
}
printf("\n\nTotal for your CIS Books is $%.1f \n"), cis_total;
printf("\nMath Book Totals:\n");
for(int i=0; i<cost2; i++)
{
if(i == cost2-1)
puts(math_books[i]);
else
puts(math_books[i]);
}
for(int i=0; i<cost2; i++)
{
math_total +=math_cost[i];
printf("\nCost of your Math Books: $%.1f\n"), cis_cost[i];
}
printf("\nTotal for your Math Books is $%.1f\n"), math_total;
total_sales = cis_total + math_total;
printf("Total Sales are $%.1f\n"), total_sales;
double finance = total_sales * FIN_AID;
printf("\nThe %.1f percent paid by Financial Aid is $%.1f\n"), FIN_AID*100, finance;
printf("The total amount you must pay out of pocket is %.1f \n"),total_sales-finance;
puts(cis_books[0]);
return 0;
}