use strcmp in if function

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
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
char kode[5],jl[5][25];
int harga[5],i;
garis()
{
cout<<"=========================================="<<endl;
}
hitung()
{
if(strcmp(kode[i],"AD01")==0)
{
strcpy(jl[i],"Some One Like You");
harga[i]=10000;
}
else if(strcmp(kode[i],"LP02")==0)
{
strcpy(jl[i],"Irridescent");
harga[i]=12500;
}
else if(strcmp(kode[i],"LG03")==0)
{
strcpy(jl[i],"Born This Way");
harga[i]=15000;
}
else
{
strcpy(jl[i],"Start Over");
harga[i]=17500;
}
}

main()
{
char lagi,bo[10];
int jm[5],tot[5],jb=0,jd;
atas:
clrscr();
cout<<"\t\tDownload Musik \"Ting Ting\""<<endl;
garis();
cout<<"Kode    Judul Lagu          Harga/Download"<<endl;
garis();
cout<<"AD01    Some One Like You   Rp 10.000,-"<<endl;
cout<<"LP02    Irridescent         Rp 12.500,-"<<endl;
cout<<"LG03    Born This Way       Rp 15.000,-"<<endl;
cout<<"BY04    Start Over          Rp 17.500,-"<<endl;
garis();
cout<<endl<<endl;
cout<<"Jumlah Data :";cin>>jd;
for(i=1;i<=jd;i++)
{
cout<<"Download no-"<<i<<endl;
cout<<"Kode Lagu\t\t\t:";cin>>kode[i];
cout<<"Jumlah Download\t:";cin>>jm[i];
}
clrscr();
garis();
cout<<"No    Judul        Harga    Jumlah   Total"<<endl;
garis();
for(i=1;i<=jd;i++)
{
hitung();
tot[i]=jm[i]*harga[i];
jb=jb+tot[i];
cout<<setiosflags(ios::left)<<setw(6)<<i;
cout<<setiosflags(ios::left)<<setw(6)<<jl[i];
cout<<setprecision(6)<<"   "<<setw(4)<<harga[i];
cout<<setprecision(6)<<"    "<<setw(4)<<jm[i];
cout<<setprecision(6)<<"     "<<setw(4)<<tot[i]<<endl;
}
garis();
cout<<"\t\t\tTotal Harga  "<<jb<<endl;
if(jb>=25000)
{
strcpy(bo,"Ringtones");
}
else
{
strcpy(bo,"Wallpaper");
}
cout<<"\t\t\tBonus\t     "<<bo<<endl;
cout<<"\tIngin Input Lagi?";cin>>lagi;
if(lagi=='Y'||lagi=='y')
{
goto atas;
}
else
{
cout<<endl<<endl;
cout<<"\t\t...:::TerimaKasih:::..."<<endl;
}
getche();
}


i dont understand with this problem. Can you solved the problem??
iam sorry if this problem very easy for you. I still learn about this.
first: if is a statement not a function
second:
1
2
3
4
5
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
#include<string.h> 


should be

1
2
3
4
#include <iostream>
#include <iomanhip>
#include <string>
#include <conio.h> 


it is proper syntax to not have a .h file and iostream is the c++ equivalent to stdio.h so you dont need the latter. because conio.h is a windows only file I dont know its c++ cousin that is probably your problem

edit:*main in c++ must be int main and all other functions can be any other var type with the addition of void which doesn't return anything
Last edited on
strcmp(kode[i],"AD01"

kode[i] is one char , and "AD01" is a null-terminated string (C string in short)

And strcmp,will be zero (0) if 2 arguments are equal, >0 if argument A is lexicographically larger than B and <0 if vice versa. <= and >= you may think of them by yourself.
Topic archived. No new replies allowed.