Data Type Mismatch Error in C++ Code: Rectification Needed [message #1862145] |
Wed, 15 November 2023 10:28 |
bretny relly 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?
|
|
|
Powered by
FUDForum. Page generated in 0.02544 seconds