Thread: data structures

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Birmingham UK
    Posts
    8

    Question data structures

    Hi

    basically what im trying to do is create a shopping program in C. I will be adding extra features later on but for now all i want it to do is for the user to enter a number 1-3 and depending on the number chosen the program displays the corresponding product and price.

    Im not very good with data structures and im sure im on the wrong track. Could someone give me a few pointers. Thanks

    Heres what ive got so far

    DVD Player £29.99
    MP3 player £39.99
    Walkman £19.99

    Code:
    #include <stdio.h>
    
    typedef struct 
    {
    char name[20];
    float price;
    
    } product;
    
    product p1,p2;
    
    
    struct product p1;
    
    p1.name="DVD Player";
    p1.price=29.99;
    
    product p2;
    
    p2.name="MP3 Player";
    p2.price=39.99;
    
    product p3;
    
    p3.name="Walkman";
    p3.price=19.99;
    
    
    int main(void)
    {
    scanf ("enter a product number %d",product),
    
        if (number == 1)                                    
            printf("%c\t%f",p1.name,p1.price); 
    
        else if (number == 2)                                     
            printf("%c\t%f",p2.name,p2.price); 
    
        else if (number == 3)                                    
            printf("%c\t%f",p3.name,p3.price);        
    
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Birmingham UK
    Posts
    8

    Red face

    whoops!

    just noticed ive posted this in the wrong section as it a c programming question not c++

    anybody now how to close this thread

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's a good generalized data structures book?
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-16-2006, 01:01 PM
  2. i need advice about data structures
    By sawer in forum C Programming
    Replies: 2
    Last Post: 04-22-2006, 03:40 AM
  3. Need some help regarding data structures
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-28-2006, 05:19 AM
  4. array of structures, data from file
    By nomi in forum C Programming
    Replies: 5
    Last Post: 01-11-2004, 01:42 PM
  5. Array Data Structures
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 06:52 PM