#include <stdio.h>
#include <string.h>

struct cd_detail
	char group[20];
	char name[50];
	int year;
	double price, playtime,costTotal;
cd[7]={{"Alan","Tibet sing",2008,51,600},
		{"Thubasa","Fly away",2007,52,700},
		{"Alan","I love China",2010,53,500},
		{"pitbull","Jump to jump",2005,54,720},
		{"pitbull","crazy mix",2009,48,630},
		{"pitbull","Let we ROCK",2010,49,608},
		{"Alan","Sakura mansume",2010,56,909}};

void main()
	char group[20];
	int k;

	printf("Enter group>");
	gets (group);


    printf("Name    \tYear   \tPrice \tPlaytime\n");

		printf("%s \t %d \t %.2f\t %.2f \t\n", cd[k].name,cd[k].year,cd[k].price,cd[k].playtime);
		printf("CostTotal >%.2f",cd[k].costTotal);

Halo guy and girls i am first time to learning programming and now my problem is how to take the CostTotal i want for after display all the details about group i try many time still no idea to write the code to find the totals

Recommended Answers

All 4 Replies

Part of your problem is that you have 6 members of the cd_detail struct (group, name, year, price, playtime, and costTotal), but you're only initializing 5 of them.

{"Alan","I love China",2010,53,500} //only 5 values here...

The value that you are failing to initialize is the value of costTotal.
The other part of your problem is likely that you are not dereferencing the array element(s) correctly. You should really rewrite your access statements as


Notice the parentheses...

Or am I misunderstanding what your problem is?

To Fbody: array[index].member will work too. Although I did not really get the problem.

It depends on how the array is declared. For this situation, it should be fine, because you only have one level of pointer indirection. But, if the array contained pointers, there would be an issue because the levels of indirection wouldn't dereference in the correct order.

In My Opinion, it's better to be consistently explicit than it is to wind up with an extremely insidious intent error because your situation changed.

You want to find the totalcost for each group?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.