- 1

Can you please help me why in the last the calculation is not happening property in the code.

In the last value of the discount variable is showing 0. #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here for(int n=4;n>0;n--) { for(int j=0;j<6;j++) { if(ages[j]>ages[j+1]) { int a=0; a=ages[j]; ages[j]=ages[j+1]; ages[j+1]=a; } } } int b = ages[0]; int discount = (b/100)*50; int ans = 50-discount; cout<<ans; return 0; }

2nd Nov 2022, 3:32 PM
Shreyansh
Shreyansh - avatar
3 odpowiedzi
+ 2
cuz b/100 is 0 if b<100 so 50*0 = 0
2nd Nov 2022, 3:48 PM
Just Some Random Guy
Just Some Random Guy - avatar
0
int b = ages[0]; float discount = (b*50)/100.0; float ans = 50.0-discount; Use this to get floating type value.
2nd Nov 2022, 4:38 PM
Just Some Random Guy
Just Some Random Guy - avatar
0
Thanks bro I got the answer
2nd Nov 2022, 4:39 PM
Shreyansh
Shreyansh - avatar