Thread: Store Front C Program

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Store Front C Program

    Hayy everyone,
    Since I am such a newbie to C programing, I was wondering if someone can help me. I want to write a program that simulate the front of a store operations common today. I want my program to look up the price and taxability of the item, computes the tax, keeps a running total, deducts from inventory the sale of the item, and finally prints out the receipt for the customer. Here is what I have now.

    Code:
    #include "stdio.h"
    #include "stdlib.h
    #define	FILENAME			"db.txt"
    #define	RECEIPT_FILE	"receipt.txt"
    #define	TAXRATE			0.065
    
    
    int Lookup_Item_Quantity(FILE *db, int item);
    double Lookup_Item_Price(FILE *db, int item);
    char Lookup_Item_Taxability(FILE *db, int item);
    double Compute_Tax(FILE *db, int item, int qty);
    int Remove_Qty_From_Inventory(FILE *db, int item, int qty);
    int Create_Receipt(FILE *db, int items[][2], int itemcnt);
    
    main() {
    int Q;
    double price;
    char tax;
    double O;
    double T;
    double N;
        
        FILE*db;
        db=fopen("db.txt", "r+");
        Q=Lookup_Item_Quantity(db, 333333);
        printf("%i", Q);
        
        FILE*db;
        db=fopen("db.txt", "r+");
        Price=Lookup_Item_Price(db, 333333);
        printf("%lf", price);
        
        FILE*db;
        db=fopen("db.txt","r+");
        tax=Lookup_Item_Taxability(db, 333333);
        printf("%c", tax);
        
        FILE*db;
        db=fopen("db.txt", "r+");
        ComputeT=Compute_Tax(db, 33333);
        printf("%i", "%lf", Q,Item);
    	
    	
    	
    } // end of main()
    
    int Remove_Qty_From_Inventory(FILE *db, int item, int qty){
    
    	int		rval=1;
    	FILE		*db2 = fopen("temp.txt", "w");
    
    
    	// ...
    	// YOUR CODE GOES HERE...
    	// Copy everything over from the db.txt file
    	//  over to the temp.txt file -- be sure to
    	//  subtract qty from the proper item
    	// ...
    	
    	
    
    	// This code renames the temporary file	
    	// to be the new database file
    	fclose(db);
    	fclose(db2);
    	remove(FILENAME);
    	rename("temp.txt", FILENAME);
    	db = fopen(FILENAME, "r+");
    	
    	
    	return rval;
    	
    } // end of Remove_Qty_From_Inventory()
    
    rewind();
    int Lookup_Item_Quantity(FILE *db, int item){
        while (in !=item){
            fscanf(db, "%i", &in);
            fscanf(db,"%lf\n" &price);
            fscanf(db, "%c", &tax);
            fscanf(db, "%i", &Q);
        }//end of while
        return Q;
    	
    } // end of Lookup_Item_Quantity()
    
    rewind();
    double Lookup_Item_Price(FILE *db, int item){
        while (in !=item){
            fscanf(db, "%i", &in);
            fscanf(db,"%lf\n" &price);
            fscanf(db, "%c", &tax);
            fscanf(db, "%i", &Q);
        }//end of while
        return price;
    	
    } // end of Lookup_Item_Price()
    
    rewind();
    char Lookup_Item_Taxability(FILE *db, int item){
        while (in !=item){
            fscanf(db, "%i", &in);
            fscanf(db,"%lf\n" &price);
            fscanf(db, "%c", &tax);
            fscanf(db, "%i", &Q);
        }//end of while
        return tax;
    	
    } // end of Lookup_Item_Taxability()
    
    rewind();
    double Compute_Tax(FILE *db, int item, int qty){
        switch(tax, Q){
            case 'O'(if O!= .99999);
            case 'T'(if T!=.06);
            case 'N'(if N!= .07);
        }//end of switchcase
            
    	
    } // end of Compute_Tax()
    
    int Create_Receipt(FILE *db, int items[][2], int itemcnt){
    	
    } // end of Create_Receipt()
    Thanks for the help!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    ...and your question is?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can't have function calls (eg, rewind()) outside of functions.

    Code:
        switch(tax, Q){
            case 'O'(if O!= .99999);
            case 'T'(if T!=.06);
            case 'N'(if N!= .07);
        }
    You should definitely read up on how a switch works. It takes an integral expression, not "tax, Q":
    Code:
        switch(input) {
        case '1':
            load_file();
            break;
        case '2':
            write_file();
            break;
        }
    And Q is a variable local to main(), which is not visible (in scope) in Compute_Tax(). Make it a global variable or pass it into the function if you want to use it.

    As for this . . .
    Code:
    	// ...
    	// YOUR CODE GOES HERE...
    	// Copy everything over from the db.txt file
    	//  over to the temp.txt file -- be sure to
    	//  subtract qty from the proper item
    	// ...
    Look up getc().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Store txt file in program
    By willc0de4food in forum Windows Programming
    Replies: 10
    Last Post: 04-16-2006, 05:44 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  4. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM
  5. Replies: 5
    Last Post: 09-08-2001, 09:18 AM