Code Help

This is a discussion on Code Help within the C++ Programming forums, part of the General Programming Boards category; im working on a basic till system Code: #include<stdio.h> void asci(void);//function prototype void till(void);//function prototype int item;//declaring variables int quantity;//declaring ...

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

    Code Help

    im working on a basic till system

    Code:
    #include<stdio.h>
    
    void asci(void);//function prototype
    
    void till(void);//function prototype
    
    
    
    int item;//declaring variables
    
    int quantity;//declaring variables
    
    int price;//declaring variables
    
    int x;//inner loop counter
    
    int y;//outer loop counter
    
    int main(void){
    
    asci();//function call
    
    	int testnum = 0;
    
    	do{
    
    		printf("\nMenu Navigation\n0 = Exit\n1 = Item Input\nEnter a menu number = ");
    
    		scanf_s("%d", &testnum);
    
    		switch(testnum) {
    
    		case 0 : continue;
    
    	//now for the loop
    	//yer baby the loop.........
    
    		case 1 :till();//function call
    
    			break;
    
    		}
    
    	
    
    	} while(testnum !=0);
    
    	printf("Loop complete\n");
    
    		return 0;
    
    	}
    
    /**********************************************************************************/
    
    /** Start of ASCI coding **/
    
    /**********************************************************************************/
    
    void asci(void)//function definition
    
    {
    
    /**print top line and ends **/
    
    	printf("\t%c",201);
    
    	for(x=1;x<60;x++)
    
    		printf("%c",205);
    
    	printf("%c\n",187);
    
    
    
    	/**print left and right edges **/
    
    	printf("\t%c			Basic Till		    	    %c\n",186,186);
    
    	printf("\t%c			Software Menu		    	    %c\n",186,186);
    
    
    
    	for(x=y;y<1;y++){ //y< sets the height of the menu
    
    		printf("\t%c",186);
    
    		for(x=1;x<60;x++)
    
    			printf("%c",' ');
    
    		printf("%c\n",186);
    
    	}
    
    
    
    		/**print bottom lines and edges **/
    
    		printf("\t%c",200);
    
    		for(x=1;x<60;x++)
    
    			printf("%c",205);
    
    		printf("%c\n\n",188);
    
    		}
    
    
    
    /**********************************************************************************/
    
    /** Start of till coding **/
    
    /**********************************************************************************/
    
    void till(void)//function definition - used for the till selection
    
    // here we add item name, quantity and price
    
    {
    	puts("\nItems List\n"); //main till functions, select items, select quantity, select price
    
    		printf("Enter Item Name = "); //Item
    
    		scanf_s("%d",&item);
    
    		printf("Enter Quantity = "); //Quantity
    
    		scanf_s("%d",&quantity);
    
    		printf("Enter Price = "); //Price
    
    		scanf_s("%d",&price);
    
    	//this wonderfull code will add it all up for you
    
    int multiply_stuff	= quantity * price; //this deals with the total item price of whats been ordered. 
    										//quantity multiplyed by price = total
    printf("Product Name: %d :: Item Quantity: %d :: Item Price: = %d :: Total For Item: = %d ",item,quantity, price, multiply_stuff);
    	}
    //end the wonderfull adding up code
    how can i get it so that the user can keep entering an item and price and such untill 0 is pressed.
    Also how can i output this information into a file or on screen?

    dan

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    What's scanf_s()?

    Code:
    puts("\nItems List\n");
    First of all, this is C. It's the same as
    Code:
    cout << "\nItems List\n\n";
    or
    Code:
    printf("\nItems List\n\n");
    puts() adds a newline onto the end of the string.

    how can i get it so that the user can keep entering an item and price and such untill 0 is pressed.
    Use a while loop. Something like this:
    Code:
    int x;
    
    while(scanf("%i", &x) && x) { // (or cin>>x)
        /* code */
    }
    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.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Also how can i output this information into a file or on screen?
    Onto the screen:
    Code:
    C:\directory>program
    Into the file file:
    Code:
    C:\directory>program > file
    Or you can program it yourself.
    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.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    6
    scanf_s is the new type of scan used in visual c++ 2005 express

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Ugh! If you say so.

    Isn't it C, though?

    [edit]
    Never mind, your whole program is C. Don't know what it's doing in here.
    [/edit]
    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.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    6
    oh did i post it wrong?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Well, this is the C++ forum. You're supposed to put C programs in the C forum.
    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.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    6
    ok sorry, anyway i have an issue i still cant figure put how to add the loop to my code.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You already have a loop.

    [edit] Oh, you mean in till(). In that case, see main() for an example. [/edit]
    Last edited by dwks; 12-10-2005 at 02:46 PM.
    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.

  10. #10
    Registered User
    Join Date
    Dec 2005
    Posts
    6
    yes but i want it to continue adding items untill i press a button as right now i add one itema nd it goes back to main menu selection

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    As I said, see main().
    Code:
    void till(void)//function definition - used for the till selection
    
    // here we add item name, quantity and price
    
    {
    	puts("\nItems List\n"); //main till functions, select items, select quantity, select price
    
    		printf("Enter Item Name = "); //Item
    
    		scanf_s("%d",&item);
    
    		printf("Enter Quantity = "); //Quantity
    
    		scanf_s("%d",&quantity);
    
    		printf("Enter Price = "); //Price
    
    		scanf_s("%d",&price);
    
    	//this wonderfull code will add it all up for you
    
    int multiply_stuff	= quantity * price; //this deals with the total item price of whats been ordered. 
    										//quantity multiplyed by price = total
    printf("Product Name: %d :: Item Quantity: %d :: Item Price: = %d :: Total For Item: = %d ",item,quantity, price, multiply_stuff);
    	}
    ->
    Code:
    void till(void)//function definition - used for the till selection
    
    // here we add item name, quantity and price
    
    {
        while(1) {
    
    	puts("\nItems List\n"); //main till functions, select items, select quantity, select price
    
    		printf("Enter Item Name = "); //Item
    
    		scanf_s("%d",&item);
    
        if(item == 0) break;
    
    		printf("Enter Quantity = "); //Quantity
    
    		scanf_s("%d",&quantity);
    
    		printf("Enter Price = "); //Price
    
    		scanf_s("%d",&price);
    
    	//this wonderfull code will add it all up for you
    
    int multiply_stuff	= quantity * price; //this deals with the total item price of whats been ordered. 
    										//quantity multiplyed by price = total
    printf("Product Name: %d :: Item Quantity: %d :: Item Price: = %d :: Total For Item: = %d ",item,quantity, price, multiply_stuff);
    }
    	}
    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.

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    6
    ahh i see what you done, thanks

    also added a few glitch fixes, were text can come garbled into other text
    Last edited by neoapple; 12-10-2005 at 02:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21