Hi mọi người.
Mình đang làm Day 2 trong 30 Dahs of Code trên HackerRank.
Đề bài như sau:
Task
Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal’s total cost.
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!
Input Format: There are 3 lines of numeric input:
The first line has a double, (the cost of the meal before tax and tip).
The second line has an integer, (the percentage of being added as tip).
The third line has an integer, (the percentage of being added as tax).
Còn đây là code:
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
double mealCost;
std::cin >> mealCost;
int tipPercent;
std::cin >> tipPercent;
int taxPercent;
std::cin >> taxPercent;
int totalCost = mealCost + (double)(mealCost * (tipPercent / 100.0)) + (double)(mealCost * (taxPercent / 100.0));
std::cout << "The total meal cost is " << totalCost << " dollars." << std::endl;
return 0;
}
Có 4 testcase nhưng chưa vượt qua testcase cuối !