harwind

harwind

Data Type Mismatch Error in C++ Code: Rectification Needed

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?

Most Liked

Eiji

Eiji

I have tried to enter some data and all seems good. Is there anything specific you found? Could you please let us know what’s your input, output and expected result?

Where Next?

Popular General Dev topics Top

AstonJ
:smiling_imp: What is your preferred syntax style and why? Perhaps we can add examples and use the code below as a simple reference poi...
New
AstonJ
Looking at @siddhant3030’s photo from the Do you blog? thread, do you cover your computer or phone camera as a security precaution? Wha...
New
chasekaylee
I’ve been using the classic notebook to-do list, but I’m curious to hear what awesome tools are out there that I am not aware of. I’m alw...
New
AstonJ
Just been adding some more portals, currently have the following languages: Apache Groovy C C# C++ Clojure CoffeeScript Crystal ...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
mafinar
I always start with excitement and then get busy on 9/10th day. This year, like the year before this, and the year before that, I intend ...
New
New
AstonJ
Things like smart speakers (such Amazon Alexa), smart TVs or other devices with built in microphones, cameras or with other features that...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
AstonJ
00:00 The Year 2022 00:38 Web3 03:28 Metaverse 05:05 AI 06:22 Databases 07:31 JavaScript 09:58 Other Trends to Know WDYT - what wi...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New