0

what's the problem here??

When I run this: #include<iostream> using namespace std; int main() { float a=10000, b=10000*0.28, c=10000*0.27, d=3600+b; cout<<"JANUARY 21-->"<<"\t"; cout<<"Basic :"<<a<<"\t"; cout<<"DA :"<<b<<"\t"; cout<<"HRA :"<<c<<"\t"; cout<<"Convance :"<<d<<"\t"; cout<<"Total :"<<a+b+c+d; return 0; } I got answer as : JANUARY 21--> Basic :10000 DA :2800 HRA :2700 Convance :6400 Total :121900 But when I run this I got answer as : #include<iostream> using namespace std; int main() { float a, b=a*0.28, c=a*0.27, d=3600+b; cout<<"Enter the amount :"; cin>>a; cout<<"JANUARY 21-->"<<"\t"; cout<<"Basic :"<<a<<"\t"; cout<<"DA :"<<b<<"\t"; cout<<"HRA :"<<c<<"\t"; cout<<"Convance :"<<d<<"\t"; cout<<"Total :"<<a+b+c+d; return 0; } This is the I have got : Enter the amount :10000 JANUARY 21--> Basic :10000 DA :0 HRA :0 Convance :3600 Total :13600 I don't know why I got different answers. Any one pls explain it.

5th Aug 2021, 5:16 AM
Keerthi Vasan
Keerthi Vasan - avatar
2 Respostas
+ 4
Bro. Try like this : #include<iostream> using namespace std; int main() { float a; cout<<"Enter the amount :"; cin>>a; float b=a*0.28, c=a*0.27, d=3600+b; cout<<"JANUARY 21-->"<<"\t"; cout<<"Basic :"<<a<<"\t"; cout<<"DA :"<<b<<"\t"; cout<<"HRA :"<<c<<"\t"; cout<<"Convance :"<<d<<"\t"; cout<<"Total :"<<a+b+c+d; return 0; }
5th Aug 2021, 5:53 AM
Sowmiyashree S
Sowmiyashree S - avatar
+ 3
You need to initialize variable a before you initialize variables b, c, d, because by default they are equal 0
5th Aug 2021, 5:54 AM
Roma Butaku
Roma Butaku - avatar