我在Xcode的终端应用程序中创建了这个,但是如何解决错误。 对不起,我是初学者。
有错误void addToTotal (float cost, int quantity)
有人能帮助我使用我的代码吗?
//
// main.m
// ShoppingList
#import <Foundation/Foundation.h>
#include <stdio.h> //? not sure if this is correct
//Gobal variables visable from any function
//------VARIABLES
int totalItems = 0;
float totalCost = 0.0;
float salesTax = 0.0925;
//decalre the functions going to be used
// we don't need to declare main() because it's built-in
//------FUNCTIONS
void addToTotal (float cost, int quantity);
float costWithSalesTax (float price);
//------MAIN PROGRAM
int main(int argc, const char * argv[])
{
@autoreleasepool {
float budget = 10000.00;
// make a new line
printf("\n");
//set the price for each item
float laptopPrice = 1799.00;
float monitorPrice = 499.80;
float phonePrice = 199.00;
addToTotal(laptopPrice, 2);
addToTotal(monitorPrice, 1);
addToTotal(phonePrice, 4);
//display a line then the final total
printf("----------------------\n");
printf("TOTAL for %i items: $%5.2f\n\n", totalItems, totalCost);
if(totalCost < budget)
{
printf("You came in under your budget!");
}
else
{
printf("Your're over your budget. Time to talk to finance.\n\n");
}
}
// There's an error in here asking me to put ; after this method declaration.
void addToTotal (float cost, int quantity)
{
printf(" Adding %i items of the cost $%5.2f\n", quantity, cost);
// find the cost for this item by multiple costs by quantity.
// and get the real costs by applying sales tax.
float calculatedCost = cost * quantity;
float realCost = costWithSalesTax(calculatedCost);
// and this amount to the total, and increase the total number
// of items purchased
totalCost = totalCost + realCost;
totalItems = totalItems + quantity;
printf("Subtotal for %i items: $%5.2f\n", totalItems, totalCost);
}
// There's an error in here asking me to put ; after this method declaration.
float costWithSalesTax (float price)
{
// remember sales tax is a global variable
float taxAmount = price * salesTax;
float subTotal = price + taxAmount;
return subTotal;
}
}
return 0; // also this has the error "expected identifier or (" error
}
答案 0 :(得分:1)
您正尝试在addToTotal()
的实施中内实施costWithSalesTax()
和main()
个功能。将它们移到收盘}
下方。
您的代码末尾还有一个额外的}
。具体来说,是return 0;
之前的那个。删除它。