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

  • Home
  • SEARCH
  • 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 5952331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:40:00+00:00 2026-05-22T17:40:00+00:00

Hey guys, I’m still learning C and have created a virtual cash register. One

  • 0

Hey guys, I’m still learning C and have created a virtual cash register. One problem, how do I display my output results after the total is calculated that’s all the program renders. I also can’t figure out how to instantiate a cashTendered method where the user will give the program (20.00 for example) and subtract that from it’s total amount of the items Also, if you spot any additional errors and/or have any ideas, please let me know.

#include <stdio.h>

int main() {

    // Instantiate the Variables    
    float itemPrice1 = 0, // Represents the item's price
          itemPrice2 = 0, // Represents secondary item price
          itemQuantity1 = 0, // Accounts for the specified quantity of the item
          itemQuantity2 = 0,
          subTotal1 = 0, // Amount prior to taxAmount 
          subTotal2 = 0,
          taxAmount = 0, // Percentage rate of 7% or 0.07
          totalAmount = 0, // Accounts for totalAmount including taxAmount
          cashTendered = 0, // Amount given towards totalAmount price
          change = 0; // Deductable given after payment

// Implementation 

    printf("Enter the quantity and price for Paint :");
    scanf("%f %f", &itemQuantity1, &itemPrice1);
    printf("Enter the quantity and price for Blue Brush :");
    scanf("%f %f", &itemQuantity2, &itemPrice2);



    subTotal1 = itemPrice1 * itemQuantity1; 
    subTotal2 = itemPrice2 * itemQuantity2; 
    taxAmount = 0.07*(subTotal1 + subTotal2);
    totalAmount = subTotal1 + subTotal2 + taxAmount;
    change = cashTendered - totalAmount;

// Program's output results

    printf("Your total is: %.2f", totalAmount);
    scanf("%f", totalAmount);
    printf ("Here is your receipt :\n");
    printf ("JcPenny Stores\t\t\n");
    printf ("Dayview Mall\t\t\n");
    printf ("Article 1\t\t\t 1 @", itemPrice1, subTotal1);
    printf ("Article 2\t\t\t 2 @", itemPrice2, subTotal2);
    printf("Sub Total\t\t%.2f\n", subTotal1+subTotal2);
    printf("Sales Tax(7%%)\t\t%.2f\n", taxAmount);
    printf("Total Amount\t\t\t%.2f\n", totalAmount);
    printf("Cash Tendered\t\t\t%.2f\n", cashTendered);
    printf("Change\t%.2f\n\n", change);
    printf("Thank you for shopping with us!");

    return 0;
}
  • 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-05-22T17:40:01+00:00Added an answer on May 22, 2026 at 5:40 pm

    Questions

    cashTendered method

    You can’t create a (simple) cashTendered method (as a void function) with the current layout because all of your variables are only visible inside the scope of the main function. You would need to either pass all of your data to the cashTendered method (making structs would make this significantly less painful- see below) or make all of your variables global (generally considered to be a bad idea, for a number of complicated reasons).

    Suggestions

    Combining

    An item should be a struct, with members price and quantity (both should be ints: see "Numeric Types" below). Subtotal doesn’t really need to be a member of the item structure, as it’s a property of the total transaction and not the item.

    Mistakes

    Numeric types

    You should really be using integers rather than floats for your prices, since you’re not counting a fractional amount of dollars but an integral number of cents (all dollar prices should be multiplied by 100).

    For example, when you mark a $10.00 item down by a third, you want your new price to be $6.66, not $6.666666666666. While printf will adjust your output to two places, it won’t adjust your underlying math- it will report that somebody paying $6.66 won’t be giving enough money (since they’ll be short two-thirds of a cent).

    There are other issues you’ll run into since float is not a decimal floating point type (6.66 – (6.65 + 0.01) may not equal zero, for instance).

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

Sidebar

Related Questions

Hey guys, I have a problem. I have situation where domain in m_domainTable starts
hey guys, I have mypage.com/user-login.php?action=register and I want to be able to call mypage.com/register
hey guys, i have a usercontrol within the default email compose form, I want
hey guys, i have a string which contains say 100 words, now i want
hey guys, I have an input field that looks for matched characters on a
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Hey right now I'm using jQuery and I have some global variables to hold

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.