Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:14:06+00:00 2026-06-16T03:14:06+00:00

I have created this in a terminal application in Xcode but usure how to

  • 0

I have created this in a terminal application in Xcode but usure how to remedy the errors.
Sorry I’m a total beginner.
There errors are at

void addToTotal (float cost, int quantity)

Would someone be able to help me with my code?

//
//  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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:14:07+00:00Added an answer on June 16, 2026 at 3:14 am

    You’re trying to implement your addToTotal() and costWithSalesTax() functions inside of the implementation of main(). Move them below the closing } instead.

    You also have an extra } at the end of your code. Specifically, the one before the return 0;. Remove it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
This may be an incredibly stupid question, but I have a web application that
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have created this Fiddle with this code: This is my problem I want
I have created this function to check abecedarian with while loop (A word is
To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I have just created this table: create table dbo.OrderTypes ( ID smallint primary key
I have created something like this and this . In effect I have a
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I have created my database by this sql query: (CREATE DATABASE + DBName +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.