My Program Can't Run

Hello guys im newbie...

i try create one program with borland C++ 5.02. but whne i try to run program found error and stopping program.
for my task in school. please help me cos this task for examination.

code like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <conio>
#include <stdio>
#include <iostream>
#include <iomanip>
#define bersih() clrscr()

garis()
{cout<<"============================================================================"<<endl;}
main()
{
struct
{
char hari[10],tgl[3],bulan[10],tahun[5];
}service;

char kode[4][25], kol[4][25],*jenis[25],*namol[25],lagi;
int i,a,harga[25],jumbay[25],total=0,bayar,kembali;

awal:
bersih();
cout<<" \tBENGKEL MOTOR MEGALOBEAT"<<endl;
garis();
cout<<endl;
cout<<" Service Motor         [SMT]  : Rp. 25.000"<<endl;
cout<<" Service MOBIL         [SMB]  : Rp. 55.000"<<endl;
cout<<" Ganti Oli             [GTO]  : Rp. 30.000"<<endl;
cout<<endl;
garis();
cout<<" Hari    : ";cin>>service.hari;
cout<<" Tanggal : ";cin>>service.tgl;
cout<<" Bulan   : ";cin>>service.bulan;
cout<<" Tahun   : ";cin>>service.tahun;
cout<<endl;
cout<<" Masukkan Jumlah Kendaraan Yang Di Service : ";cin>>a;
cout<<endl;
for(i=1;1<=a;i++)
{
cout<<" Data ke - "<<i<<endl;
cout<<endl;
cout<<" Masukan Kode Service [SM/SG/GO]      : ";cin>>kode[i];
cout<<endl;
cout<<" Masukan Kode Oli [1/2/3/4]           : ";cin>>kol[i];
cout<<endl;
if (!strcmp(kode[i],"SM")||!strcmp(kode[i],"sm"))
{strcpy(jenis[i],"Service Motor");
   if(!strcmp(kol[i],"0"))
   {namol[i]=" "; harga[i]=25000;}
	else
   {namol[i]=" "; harga[i]=25000;}
   }
else
if (!strcmp(kode[i],"SG")||!strcmp(kode[i],"sg"))
{strcpy(jenis[i],"Serv. & Ganti Oli");
   if(!strcmp(kol[i],"1"))
   {namol[i]="Enduro"; harga[i]=56000;}
	else
   if(!strcmp(kol[i],"2"))
   {namol[i]="Castrol"; harga[i]=57000;}
   else
   if(!strcmp(kol[i],"3"))
   {namol[i]="Repsol"; harga[i]=58000;}
   else
   if(!strcmp(kol[i],"4"))
   {namol[i]="Top One"; harga[i]=59000;}
   else
   {namol[i]="Kode Salah"; harga[i]=0;}
   }
else
if (!strcmp(kode[i],"GO")||!strcmp(kode[i],"go"))
{strcpy(jenis[i],"Ganti Oli");
   if(!strcmp(kol[i],"1"))
   {namol[i]="Enduro"; harga[i]=31000;}
	else
   if(!strcmp(kol[i],"2"))
   {namol[i]="Castrol"; harga[i]=32000;}
   else
   if(!strcmp(kol[i],"3"))
   {namol[i]="Repsol"; harga[i]=33000;}
   else
   if(!strcmp(kol[i],"4"))
   {namol[i]="Top One"; harga[i]=34000;}
   else
   {namol[i]="Kode Salah"; harga[i]=0;}
   }
else
{strcpy(jenis[i],"Kode Salah");
namol[i]=" "; harga[i]=0;}

jumbay[i]=harga[i];
total=jumbay[i]+total;
cout<<endl;
}
bersih();
cout<<" \tBENGKEL SONIC GEAR"<<endl;
garis();
cout<<" Hari, : "<<service.hari; cout<<" Tanggal : "<<service.tgl; cout<<" "<<service.bulan;cout<<" "<<service.tahun;
cout<<endl;
garis();
cout<<"No. | No. Plat | Jenis Service     | Oli      | Jumbay "<<endl;
garis();
for(i=1;i<=a;i++)
{
cout<<setiosflags(ios::left)<<setw(6)<<i;
cout<<setiosflags(ios::left)<<setw(19)<<jenis[i];
cout<<setiosflags(ios::left)<<setw(19)<<namol[i];
cout<<setprecision(2)<<" "<<jumbay[i]<<endl;
cout<<endl;
}
cout<<endl;
garis();
cout<<" Total Bayar  : Rp. "<<total<<endl;
cout<<endl;
cout<<" Bayar        : Rp. ";cin>>bayar;
kembali=bayar-total;
cout<<endl;
cout<<" Kembali      : Rp. "<<kembali<<endl;
garis();
cout<<"Mau Input Lagi? [Y/T] : ";cin>>lagi;
if (lagi=='Y'||lagi=='y')
goto awal;
else
goto akhir;
getch();
akhir:
}


thanks
Do you know how to use a debugger?

Gotos are almost never justified in C++. Try using normal control structures and loops.
Indent your code.
for(i=1;1<=a;i++) a is uninitialized. Array index goes from 0 to n-1

main must return int
garin must have a return type
Last edited on
hi friend..., i tried to understand what you up to with your program, but i confused by
SMT/SMB/GTO followed by SM/SG/GO

I assumed GTO and GO mean "Ganti Oli" but my froblem is why there is GO after GTO ?

btw you know better about what you up to;

i created a similiar program inspired from your program, its compiled with Dev-C++ and Cfree-5 and work fine.
this is it :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;


class service
	{
		public:
		string Kendaraan;
		string JenisService;
		string Oli;
		int BayarService,BayarOli,TotalBayar;
		service()
			{
				BayarService = 0;
				BayarOli = 0;
				TotalBayar = 0;
				Kendaraan = " ";
				Oli = " ";
				JenisService = " ";
			}
		bool CekKendaraan(string KodeKendaraan)
			{
				if((KodeKendaraan == "mb")||(KodeKendaraan =="MB"))
					{
						Kendaraan = "Mobil";
						return true;
					}
					else if((KodeKendaraan == "mt")||(KodeKendaraan =="MT"))
					{
						Kendaraan = "Motor";
						return true;
					}
					else
					{
						return false;
					};
				};
		bool CekOli(int KodeOli)
			{
				switch(KodeOli)
					{
						case 1:
							Oli = "Castrol";
							BayarOli = 60000;
							return true;
							break;
						case 2 :
							Oli = "Enduro";
							BayarOli = 55000;
							return true;
							break;
						case 3 :
							Oli = "Top1";
							BayarOli = 50000;
							return true;
						default :
							BayarOli = 0;
							return false;							
					};
			};
		bool CekService(string ServiceParam)
			{
				if((ServiceParam == "sm")||(ServiceParam == "SM"))
					{
						JenisService = "Service Mesin";
						BayarService = 100000;
						return true;
					}
					else if((ServiceParam == "go")||(ServiceParam == "GO"))
					{
						JenisService = "Ganti Oli";
						return true;
					}
					else
					{
						return false;
					};
			};
		int Bayar()
			{
				return BayarService + BayarOli;
			};
			
	};
bool CekKendaraan(string KodeKendaraan)
			{
				if((KodeKendaraan == "mb")||(KodeKendaraan =="MB"))
					{
						return true;
					}
					else if((KodeKendaraan == "mt")||(KodeKendaraan =="MT"))
					{
						return true;
					}
					else
					{
						return false;
					};
				};
;
int main()
	{
		string vehicle;
		int manyvehicle;
		string torepair;
		int choiceoli;
		int totalsum = 0;
				
		cout<<"Welcome to FORWARD TO BACKWARD service";
		cout<<"\nOur Services are : ";
		cout<<"\n[MB]Mobil / Car";
		cout<<"\n[MT]Motor / Bike";
		do
		{
			cout<<"\nChoose the Vehicle (MB/MT) : ";cin>>vehicle;
		}while(!CekKendaraan(vehicle));
		
		cout<<"\n___________________________________";
		
		
		do
		{
			cout<<"\nHow many "<<vehicle<<" do you want to repair : ";cin>>manyvehicle;
		}while(manyvehicle < 1);
		service myvehicle[manyvehicle];
		
		for(int i=0;i< manyvehicle;i++)
			{
				myvehicle[i].CekKendaraan(vehicle);
				do
				{
					system("cls");
					cout<<"\nour services for your "<<vehicle<<" no. "<<i+1<<" are";
					cout<<"\n[SM] Service Machine";
					cout<<"\n[GO] Ganti Oli";
					cout<<"\nChoose which one (SM/GO) : ";cin>>torepair;
				}while(!myvehicle[i].CekService(torepair));
				if((torepair == "go")||(torepair=="GO"))
                                     {
                                     do
        				{
        					system("cls");
        					cout<<"\nwhat kind of oil do you want to use for "<<vehicle<<" no."<<i+1;
        					cout<<"\n[1] Castrol";
        					cout<<"\n[2] Enduro";
        					cout<<"\n[3] Top 1";
        					cout<<"\nChoose which one (1/2/3) : ";cin>>choiceoli;
        				}while(!myvehicle[i].CekOli(choiceoli));
                                     };
				
			};
		system("cls");
		cout<<"\nThis is the Sum of your choice : ";
		for(int i=0;i< manyvehicle;i++)
			{
				cout<<"\n\n______________________________";
				cout<<"\nfor "<<myvehicle[i].Kendaraan<<" no. "<<i+1;
				cout<<"\nUsed Service : ";
				cout<<myvehicle[i].JenisService<<" Rp. "<<myvehicle[i].BayarService;
				cout<<"\nUsed oil : ";
				cout<<myvehicle[i].Oli<<" Rp. "<<myvehicle[i].BayarOli;
				cout<<"\nTotal for this Vehicle : Rp. "<<myvehicle[i].Bayar();
				cout<<endl;
				totalsum = totalsum+myvehicle[i].Bayar();
			};
		cout<<"\n\n______________________________________________";
		cout<<"\nTotal sum for "<<manyvehicle<<" "<<myvehicle[1].Kendaraan;
		cout<<" is Rp. "<<totalsum;
		cout<<"\n\n______________________________________________";
		cout<<"\n\n______________________________________________";
		cout<<"\n                 THANKYOU                 ";
		
		cout<<"\n\n\n";
		system("pause");
		return 0;
	}


there is no GOTO required in this codes, but every task done quietly, its look complicated with class to define object. but its verry usefull especially if you going to make more than thousand object, every tasks like bayar oli ,bayar service and total bayar are done within object itself,
in large project you cant use GOTO to control the loop, and procedural programs are verry hard to maintain when its hit thousand line of codes, thats why i like c++ and it OOP style.

i see soo many array created in your codes
1
2
char kode[4][25], kol[4][25],*jenis[25],*namol[25],lagi;
int i,a,harga[25],jumbay[25],total=0,bayar,kembali;
:
i wonder how to handle it handle it when its filled with datas.
and by :
 
int harga[25];

mean your program limited to 25 objects, with OOP style you can create as much as your memory computer can accept , mean unlimited.

for me OOP style are better, easier, maintainable, readable, more usable and sexy.
and more...., i like function overload.

Topic archived. No new replies allowed.