Thread: Supermarket checkout C program

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    6

    Supermarket checkout C program

    Hi im a newbie and im not very good so far but i need to be for my university course!

    anyway i need to make a program that uses loops and adds up numbers as they're typed in, in float values, and keep a running total, and once the user enters a zero value the program should stop reading numbers and print out (a) the grand total (b) the number of items.

    Im so stuck i cant even think!

    Hope you can help cheers!

    oh forgot to say im not using scanf we have our own simpleio library.

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Please post the code

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    if you can call this code this is where im stuck!

    #include <stdio.h>
    #include "/home/simpleio.h"

    int main()

    {
    float a = 0,
    printf(" Type in price of product\n"); a = getFloat();

    while (a > 0)
    {
    printf(" Type in price of product\n");

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    what is the problem man u are facing ??

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Sure you don't mean...

    Code:
    while((a = getFloat()) != 0.0f)
    {
       /* ... do something */
    }
    
    /* print totals */
    ...?

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    i dont know how to complete it

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Ok What you are not doing is

    you are not taking any values from the user

    just use scanf for taking the user input

    Code:
    take input in a 
    
    while ( a != 0) {
      do calculation
    }

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    whats wrong with getFloat?

  10. #10
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Where is getFlot man
    ??

    Can u paste that code also if that code is on your machine how can i know, Whatz the problem what that ???

  11. #11
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    #include <stdio.h>
    #include "/home/simpleio.h"

    int main()

    {
    float a = 0,
    printf(" Type in price of product\n"); a = getFloat();

    while (a > 0)
    {
    printf(" Type in price of product\n");


    this is literally all i can think of im crap at this

  12. #12
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Is getFloat is a standard library function or a user defined function ???

    And if user defined than can you please paste the code ??

  13. #13
    Registered User
    Join Date
    Dec 2009
    Posts
    6
    standard library

  14. #14
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by tom619 View Post
    standard library
    Ok if that is the case, than what you can do

    Code:
    while (a != getFloat() {
       // Do Calculations
    }

  15. #15
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by RockyMarrone View Post
    Ok if that is the case, than what you can do

    Code:
    while (a != getFloat() {
       // Do Calculations
    }
    No. That is not any viable solution. Entering "1" then "1" will break the loop.

    I have posted a viable loop above... why not use it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM