Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Data Type Mismatch Error in C++ Code: Rectification Needed
Data Type Mismatch Error in C++ Code: Rectification Needed [message #1862145] Wed, 15 November 2023 10:28
bretny relly is currently offline bretny rellyFriend
Messages: 14
Registered: March 2023
Junior Member
I need help with a data type-related problem in my C++ code. I've tried a few different approaches and have read various sites like Scaler, 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?
Previous Topic:Some questions about plug-in installation
Next Topic: "Timestamp display in GDB possible?"
Goto Forum:
  


Current Time: Mon Jan 20 00:23:48 GMT 2025

Powered by FUDForum. Page generated in 0.02544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top