Menampilkan jumlah total terjual pada game bergenre racing (sequential file)

TABEL KODE GAME Nama Game Genre Total Terjual Harga 1011 AAAA Racing 100 2000000 1012 BBBB Action 50 1000000 1023 CCCCC Puzzle 20 50000

#include<stdio.h>
typedef struct{
	int kode;
	char Nama[10];
	char Genre[10];
	int tt;
	int harga;
}Beras;
Beras B;
FILE *game;
void input();
void output();
void total();
void rata();
void banyak();
int n,i,menu,jmlkd,jmlkd2,max,kd;
long total1,total2;
float ratatotal,rataseluruhtotal;
int seperator(int space);
main(){
		do{
		printf("Pilih Nomer Menu: "); scanf("%d",&menu);
		if(menu==1){
			input();
		}else if(menu==2){
			output();
		}else if(menu==3){
			total();
		}else if(menu==4){
			rata();
		}else if(menu==5){
			banyak();
		}
		else{
			printf("Pilih Nomer 1-5!");
		}
	}while(menu!=0);
}
void input(){
	game=fopen("Transaksi2.txt","at");
	printf("Berapa Inputan? "); scanf("%d",&n);
		for(i=0; i<n; i++){
			printf("Kode Game : ");fflush(stdin); scanf("%d",&B.kode);
			printf("Nama Game         : ");fflush(stdin); scanf("%s",&B.Nama);
			printf("Genre         : ");fflush(stdin); scanf("%s",&B.Genre);
			printf("Total Terjual         : ");fflush(stdin); scanf("%d",&B.tt);
			printf("harga      : ");fflush(stdin); scanf("%ld",&B.harga);
			fprintf(game,"%d        %s %s %d     %ld \n",B.kode,B.Nama,B.Genre,B.tt,B.harga);
		}
	fclose(game);
}
void output(){
	game=fopen("Transaksi2.txt","r");
		while(!feof(game)){
		fscanf(game,"%d        %s %s %d     %ld \n",&B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
			printf("\nKode Game : %d",B.kode);
			printf("\nNama Game         : %s",B.Nama);
			printf("\nGenre        : %s",B.Genre);
			printf("\nTotal Terjual        : %d",B.tt);
		printf("\nharga      : %ld",B.harga);
		}
	printf("\n");
	fclose(game);
}
void total(){
	total2=0;
	game=fopen("Transaksi2.txt","rt");
	fscanf(game,"%d        %s %s %d     %ld  \n",B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
		fread(&B,sizeof(B),1,game);

	if(feof(game)){
		printf("File Kosong");
	}else{
		do{
			while(!feof(game)&&(seperator(B.kode))){
				fscanf(game,"%d        %s %s %d     %ld  \n",B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
			}
			total1=0;
			while(!feof(game)&&(!seperator(B.kode))){
				total1=B.tt+B.tt;
				total2=B.tt+B.tt;
				fscanf(game,"%d        %d     %ld \n",&B.kode,&B.Nama,&B.harga);
			}
			printf("Kode Game : %ld\n", B.kode, total1);
			if(feof(game)){
				printf("Total Terjual Game Arcade : %ld\n", total2);
			}
		}while(!feof(game));
	}
	fclose(game);
}
void rata(){
	total2=0;
	jmlkd2=0;
	game=fopen("Transaksi2.txt","rt");
	fscanf(game,"%d        %s %d %d     %ld \n",&B.kode,&B.Nama,&B.harga);
	if(feof(game)){
		printf("File Kosong");
	}else{
		do{
			while(!feof(game)&&(seperator(B.kode))){
				fscanf(game,"%d        %s %d %d     %ld \n",&B.kode,&B.Nama,&B.harga);
			}
			total1=0;
			jmlkd=0;
			while(!feof(game)&&(!seperator(B.kode))){
				total1=total1+B.harga;
				jmlkd=jmlkd+1;
				total2=total2+B.harga;
				jmlkd2=jmlkd2+1;
				fscanf(game,"%d        %s %d %d     %ld \n",&B.kode,&B.Nama,&B.harga);
			}
			ratatotal=total1/jmlkd;
			rataseluruhtotal=total2/jmlkd2;
			printf("Rata rata Total Per-Barang : %0.0f\n",ratatotal);
			if(feof(game)){
				printf("Rata rata Seluruh Barang : %0.0f\n",rataseluruhtotal);
			}
		}while(!feof(game));
	}
	fclose(game);
}
void banyak(){
	game=fopen("Transaksi2.txt","rt");
	fscanf(game,"%d        %s %d %d     %ld \n",B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
	if(feof(game)){
		printf("File Kosong");
	}else{
		do{
			while(!feof(game)&&(seperator(B.kode))){
				fscanf(game,"%d        %s %d %d     %ld \n",B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
			}
			while(!feof(game)&&(!seperator(B.kode))){
				if(B.harga>max){
					max=B.harga;
					kd=B.kode;
				}
				fscanf(game,"%d        %s %d %d     %ld \n",B.kode,&B.Nama,&B.Genre,&B.tt,&B.harga);
			}
			if(feof(game)){
				printf("Paling Banyak Nilai Penjualannya : %d\n",kd);
			}
		}while(!feof(game));
	}
	fclose(game);
}

int seperator(int space){
	if(space==9999){
		return 1;
	}else{
		return 0;
	}
}

dari hasil compile dan runnya itu menu ke 3 yg untuk menampilkan void total terjual game bergenre racing saja tidak ada hasilnya, bagaimana untuk menampilkan total penjulan game khusus genre racing saja? mungkin saya ada yg salah, mohon bantuannya gan

avatar bambang785
@bambang785

3 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban