Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
310 views

I need help with a data type-related problem in my C++ code. I've tried a few different approaches and have read various articles, but I haven't had any luck. This is a sample of the code that causes issues:

#include <iostream>

int main() {
    float totalAmount;
    int discountPercentage;

    std::cout << "Enter total amount: ";
    std::cin >> totalAmount;

    std::cout << "Enter discount percentage: ";
    std::cin >> discountPercentage;

    float discountedAmount = totalAmount - (totalAmount * discountPercentage / 100);
    
    std::cout << "Discounted Amount: " << discountedAmount << std::endl;

    return 0;
}
Despite seemingly correct logic, the code is producing unexpected results. The discount calculation appears to be incorrect. What data type-related error might be causing this issue, and how can I rectify it to ensure accurate discount calculations?

in Algorithms and Problems by Expert (650 points) | 310 views

Please log in or register to answer this question.