-
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;
}
-
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