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

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1036 18703 383
New
AstonJ
Which screen resolutions do you frequently use? Note: not the resolution the display is capable of mind, but the resolution you’re using...
New
justinjunodev
Figured this would be a cool topic and maybe provide some inspiration for those who are just starting to work from home. Feel free to sha...
New
wolf4earth
Inspired by this thread about arcade games - which I initially misread as favorite arcade game soundtracks - I wanted to ask about your f...
New
AstonJ
Thought it might be worth having a dedicated thread for standing desk treadmills (for those interested, here’s our general thread on stan...
New
Exadra37
So, if we can reduce the likelihood, we can reduce the overall risk. That’s good. It’s actually very similar to a very common idea called...
New
New
dwaynebradley
In their weekly newsletter, Jared Santo from the Changelog shared this blog post by Mark Ericksen over at fly.io: What is really inter...
New
Exadra37
A modern streaming platform for mission critical workloads Redpanda is a Kafka® compatible event streaming platform. No Zookeeper®, no JV...
New
Exadra37
My brother got a VPS on https://contabo.com hosting provider, but I was not aware of them, and when my brother told me the price and spec...
New

Other popular topics Top

AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
hilfordjames
There appears to have been an update that has changed the terminology for what has previously been known as the Taskbar Overflow - this h...
New
New
RobertRichards
Hair Salon Games for Girls Fun Girls Hair Saloon game is mainly developed for kids. This game allows users to select virtual avatars to ...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New