We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intmealCost=(int)mealCost;//intmealCost will be 14.
if((mealCost-intmealCost)>0.5)
printf("%d",intmealCost+1);
else
printf("%d",intmealCost);
i correct your code into:
double meal;
float tax,tip;
double total; //change int to double
scanf("%lf",&meal);
scanf("%e",&tip);
scanf("%e",&tax);
tip=meal*(tip/100);
tax=meal*(tax/100);
total=meal+tip+tax; //if total=14.31 and you didnt change ,it will be 14.
int inttotal=(int)total;
if(total-inttotal>0.5)printf("The total meal cost is %d dollars.",inttotal+1);
else
printf("The total meal cost is %d dollars.",inttotal);
return 0;
my english isnt good.hope it can help you.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 2: Operators
You are viewing a single comment's thread. Return to all comments →
double mealCost=14.31;
int intmealCost;
intmealCost=(int)mealCost;//intmealCost will be 14.
if((mealCost-intmealCost)>0.5)
else
i correct your code into:
my english isnt good.hope it can help you.