Results 1 to 5 of 5

Thread: Help with this code please.

  1. #1
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default Help with this code please.

    Code:
    // Program to capture stock information from data given.
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    int main()
    {
    	struct stockRec;
    	char name [21];
    	float price;
    	char stock_num[7];
    	int amount;
    	int reorder;
    }elementinfo;
    
    
    void getData(void);
    void showData(void);
    
    {
    	void getData (struct stockRec);
    	printf("Enter name, price, stock number, amount in stock and reorder level");
    	scanf("%s,%.1f,%s,%d,%d; &elementinfo.name, &elementinfo.price, &elementinfo.stock_num, &elementinfo.amount, &elementinfo.reorder);
    	return 0;
    }
    	
    	void showData(void)
    {	
    		printf("The stock element name is: %s\n",elementinfo.name);
    	    
    		printf("The price is: %.2lf\n ",elementinfo.price);
    		
    		printf("The stock number is: %d\n",elementinfo.stock_num);
    		
    		printf("The amount in stock is: %d\n",elementinfo.amount);
    		
    		printf("The reorder level is: %d\n",elementinfo.reorder);
    		
    }
    plz help me!!
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    plz help me!!
    With what?
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  3. #3
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    yeah, thats one messed up c programm still

    I dont even know where to start explaining where you went wrong.

  4. #4
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default You definitely need help

    Fixed it. I aded a few comments.
    Code:
    // Program to capture stock information from data given.
    #include <stdio.h>		// used for user input and output
    #include <conio.h>		// we only use this for getch() -- stop the console from exiting before user sees output
    //#include <stdlib.h>	// we dont need this right now
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // structure definition -- defined before using in function prototypes below
    ///////////////////////////////////////////////////////////////////////////////////////////////
    struct stockRec
    {
    	char name [21];
    	char stock_num[7];
    	int amount;
    	int reorder;
    	float price;
    } ;
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    //	function prototypes ( headers or declaration ) 
    //		like variables, functions have to be declared before being called (in main below)
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    struct stockRec getData( void );
    void showData( struct stockRec );
    //int main(  void ); // this is optional... since we never call main ( before main is called by the system)
    
    // the main module -- this does not have to be declared like the other functions above
    int main()
    {
    	struct stockRec elementinfo;	// declare an instance of the structure
    
    	elementinfo = getData();		// initialize structure with our function
    	showData( elementinfo );		// display information the user entered on screen
    
    	// showData( getData() );		// you could have done it all like this... its no better
    
    	getch();						// wait for user input before continuing
    	return 0;						// indicate a normal exit normal
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////////////
    // function definitions - actually the function definitions started at main above
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    // Gets input from user and returns a stock record
    struct stockRec getData()
    {
    	// instance of stock record to store user input
    	struct stockRec info; 
    
    	// prompt user for input
    	printf("Enter name, price, stock number, amount in stock and reorder level : ");
    
    	// read user input into stock record member fields
    	scanf("%s%f%s%d%d", &info.name, &info.price, &info.stock_num, &info.amount, &info.reorder);
    	
    	// return the information ( stock record )
    	return info;
    }
    
    // Displays the state of a stock record passed on the screen
    void showData(struct stockRec info)
    {	
    	printf("The stock element name is: %s\n", info.name);
    	printf("The price is: %.2lf\n ", info.price);
    	printf("The stock number is: %s\n", info.stock_num);
    	printf("The amount in stock is: %d\n", info.amount);
    	printf("The reorder level is: %d\n", info.reorder);
    }
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

  5. #5
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default

    got this question in a test doubt me pass then but thanks anyway.
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •