Is there something wrong in these if statements..?

This program outputs only..

Enter number of new members:3
Enter the card type:Bronze
Enter the Bill amount(Rs.):34532
Do you need to continue ?y
Enter number of new members:

It doesnt output the x
Can anyone show me the error.?
thanks..

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
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char exit;
int m;
double am;
char name[20];
int x;

do
{
cout<<"Enter number of new members:";
cin>>m;
cout<<"Enter the card type:";
cin>>name;
cout<<"Enter the Bill amount(Rs.):";
cin>>am;

if((m<=3)&&(m>=1)&&(name=="Gold"))
{
x=am-(am*0.18);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m<=3)&&(m>=1)&&(name=="Silver"))
{
x=am-(am*0.15);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m<=3)&&(m>=1)&&(name=="Bronze"))
{
x=am-(am*0.10);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}

if((m<=10)&&(m>=4)&&(name=="Gold"))
{
x=am-(am*0.22);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m<=10)&&(m>=4)&&(name=="Silver"))
{
x=am-(am*0.17);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m<=10)&&(m>=4)&&(name=="Bronze"))
{
x=am-(am*0.12);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}

if((m>10)&&(name=="Gold"))
{
x=am-(am*0.30);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m>10)&&(name=="Silver"))
{
x=am-(am*0.20);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}
if((m>10)&&(name=="Bronze"))
{
x=am-(am*0.18);
cout<<"Amount need to be Paid(Rs.): "<<x<<endl;
}

if((m<1)&&((name=="Gold")||(name=="Silver")||(name=="Bronce")))
{
cout<<"Amount need to be Paid(Rs.): "<<am<<endl;
}
cout<<"Do you need to continue ?";
cin>>exit;

      if((exit=='n')||(exit=='N'))

       break;



}
 while((exit=='y')||(exit=='Y'));

return 0;
}
Last edited on
char name[20]; &&(name=="Gold")

You can't use == to compare characters in a character array, you'd need to use strcmp. http://www.cplusplus.com/reference/cstring/strcmp/

If you make name a string instead of a character array, you could use ==.

I might suggest having the user enter 1,2 or 3 or (G, S or B) to represent the actual choices of Gold, Silver or Bronze. Check that they've entered a valid choice. Otherwise, you're relying on them to spell the name exactly as you have it. (and check line 69 - you have a typo on bronze)

Thanks..
Topic archived. No new replies allowed.