Thread: Noob with a question,any help would be greatly appreciated :)

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    18

    Noob with a question,any help would be greatly appreciated :)

    Code:
    #include <stdio.h>
    #include <conio.h>
    static void forcefloat(float*p)
    {
    float f=*p;
    forcefloat(&f);
    }
    struct client
    {
    	char client[30];
    };
    struct client data[30];
    struct seller
    {
    	char ne[30];
    };
    struct seller data2[30];
    struct product
    {
    	char np[30];
    	float pp;
    	int cp;
    };
    struct product data3[30];
    struct store
    {
    	char nt[30],fecha[20];
    };
    struct store data4[30];
    struct cpp
    {
    	int cpp;/*quantity of diffrent products*/
    	float stt,tt;/*counter for subtotal(stt) and total(tt)*/
    };
    struct cpp data5;
    void read(int);
    void show(int);
    void main()
    {
    	int i;
    	clrscr();
    	printf("\nHow many clients are going to be evaluated:");
    	scanf("%d",&i);
    	read(i);
    	show(i);
    	getch();
    }
    void read(int i)
    {
    	int j,z=0,cpp;
    	float st,sttt,t,tt=0,stt=0;
    	clrscr();
    	for(j=0;j<i;j++)
    	{
    		printf("Insert name of the store: ");
    		scanf(" %[^\n]",data4[j].nt);
    		printf("\nInsert current date: ");
    		scanf(" %[^\n]",data4[j].fecha);
    		printf("\nInsert client name: ");
    		scanf(" %[^\n]",data[j].client);
    		printf("\nInsert seller name: ");
    		scanf(" %[^\n]",data2[j].ne);
    		printf("\nInsert the amount of diffrent products the client bought: ");
    		scanf("%d",&data5.cpp);
    		for(z=0;z<data5.cpp;z++)
    		{
    			printf("\nInsert name of product number %d: ",z+1);
    			scanf(" %[^\n]",data3[z].np);
    			printf("\nInsert the amount bought of said product: ");
    			scanf("%d",&data3[z].cp);
    			printf("\nInsert price of the product: ");
    			scanf("%f",&data3[z].pp);
    			st=(data3[z].cp*data3[z].pp);/*subtotal before tax*/
    			data5.stt=data5.stt+st;
    			sttt=(0.15*st);
    			t=(st+sttt);/*total after tax*/
    			data5.tt=data5.tt+t;
    		}
    	clrscr();
    	}
    }
    void show(int i)
    {
    
    	int j,z;
    	clrscr();
    	for(j=0;j<i;j++)
    	{
    		printf("\n\t\t\t\tStore %s",data4[j].nt);
    		printf("\t\t\t%s",data4[j].fecha);
    		printf("\n\nClient %s",data[j].client);
    		printf("\nSeller %s",data2[j].ne);
    		for(z=0;z<data5.cpp;z++)
    		{
    			printf("\n\nProduct %s",data3[z].np);
    			printf("\nQuantity of product: %d",data3[z].cp);
    			printf("\nPrice of product: %.2f",data3[z].pp);
    		}
    		printf("\n\nSub-Total: %.2f",data5.stt);
    		printf("\nIVA: 15 Percent");
    		printf("\n\nTotal: %.2f",data5.tt);
    	}
    }
    Ok so what im trying to do here is a receipt, program is supposed to ask how many clients, and how many diffrent products each client takes, then calculate sub-total before taxes, then total(with taxes). Ok so im using arrays and structures, my problem is at the moment of showing the information of said receipts on the screen it shows the products of the 2nd client only(if its 2 clients), if its 3 then only the products of the 3rd, etc
    So for example it would show the receipt for the 1st client just fine, it prints name, salesmen, date, etc but sadly it shows the products, subtotal and totals of the 2nd client i know my for cycle or my array is somehow messed up. Any ideas how to fix this? Any help would be appreciated.
    Sorry for some of the code not being in english im latin
    Last edited by yrostran; 05-11-2006 at 01:26 AM.

  2. #2
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    see if this helps

    1. you are using conio.h thats a non standarda library, so dont use it.
    2. you shouldnt intialize main to void like void main(), just use main instead.
    3. I dont know what is that getch doing i took it off.
    4. the clrscr(); was given me an error in my compiler and iam using linux.

    ohh the program keeps asking over and over again. I think because i move the getch its continues in a loop and it dosent stop asking for questions, you need to put something that will terminating after inserting and ammount of clients.

    Well see if this helps

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    18
    no actually it asks and askes because in void leer() i have a series of questions the user inputs in this case me,that askes how many clients(in other words how many receipts),then askes name of the store,current date,then it asks how many diffrent products the 1st client bought,and so forth when it comes to the 2nd cycle(if its only 2 clients).
    Now my problem is it reads and prints on the screen everything just fine except when i get to reading how many diffrent products each client buys and read what those products are.The problem is when i print the info on screen it takes the last products inputted for client number 2(if working with 2 clients) so instead of having for example:

    client 1
    salesman
    product 1(for example here pencil)
    product 2(for example here notebook)

    So lets say for example i input this info for client1,and then input 2 other diffrent products for client2 Ex.pant,bookbag,when its said and done on screen it will be:

    client1
    salesman
    pant
    bookbag

    client2
    salesman
    pant
    bookbag

    So instead of client1 having pencil and notebook it has the products of the last clients products if its 3 clients then all of them have the same products.
    So there's my dilema,i know there's something wrong with my for loop and my array but havent had any luck fixing it so far.So any help would be appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noobie question, all help greatly appreciated!
    By axehero in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2007, 09:47 PM
  2. Noob Question....Any help appreciated
    By RandomX in forum C Programming
    Replies: 29
    Last Post: 11-22-2006, 04:43 AM
  3. Noob: needs help with file I/O
    By crws416 in forum C Programming
    Replies: 2
    Last Post: 03-06-2006, 09:35 AM
  4. Any assistance would be greatly appreciated
    By iiwhitexb0iii in forum C Programming
    Replies: 18
    Last Post: 02-26-2006, 12:06 PM
  5. Your help would be greatly appreciated
    By Sway2 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2002, 07:55 AM