1

我已经在 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
}
4

1 回答 1

1

您正在尝试. addToTotal()_ 而是将它们移到收盘价下方。costWithSalesTax()main()}

}您的代码末尾还有一个额外的内容。具体来说,在return 0;. 去掉它。

于 2012-12-13T03:11:41.160 回答