
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
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?
1
Popular General Dev topics

The obligatory speed test thread :smiley:
Check here: https://www.speedtest.net
When complete, click on the share link and copy and pas...
New

Have you seen the new features that will be available in the upcoming C# 9 release?
C# is taking a lot of input from functional l...
New

: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

Hi everyone! I have been in the professional industry for ~2 years now coming from a boot camp. I started a base foundation by programmin...
New

Inspired by this tweet by @dasdom
Even if you take out all the damage being done by humans, our planet has about 50B years before bein...
New

Hi there! I have some old Bose in ear noise cancelling headphones that have worked like a champ for the past 3 years and was maybe due fo...
New

TLDR
Hacking 30 Mobile Apps and their APIs with consent of some of the major providers in the area.
100% success rate in hacking the AP...
New

Hi everyone… I’m so sorry about the delay in getting this thread up, I’ve just been so busy :see_no_evil:
Are there any book clubs you’d...
New

A modern streaming platform for mission critical workloads
Redpanda is a Kafka® compatible event streaming platform. No Zookeeper®, no JV...
New

Just wondering whether you have a preference (I know I do!)
poll
New
Other popular topics

A thread that every forum needs!
Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
New

“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin
Even when you’re ultimately right about what the future ho...
New

Small essay with thoughts on macOS vs. Linux:
I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New

Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New

Hi folks,
I don’t know if I saw this here but, here’s a new programming language, called Roc
Reminds me a bit of Elm and thus Haskell. ...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

Author Spotlight:
VM Brasseur
@vmbrasseur
We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New

A Brief Review of the Minisforum V3 AMD Tablet.
Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New

I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc.
However, I don’t...
New
Categories:
Sub Categories:
- All
- In The News (10002)
- Dev Chat
- Questions (30)
- Resources (118)
- Blogs/Talks (26)
- Jobs (3)
- Events (14)
- Code Editors (58)
- Hardware (57)
- Reviews (4)
- Sales (15)
- Design & UX (4)
- Marketing & SEO (1)
- Industry & Culture (14)
- Ethics & Privacy (19)
- Business (4)
- Learning Methods (4)
- Content Creators (7)
- DevOps & Hosting (9)
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /ash
- /vscode
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /react-native
- /textmate
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /django
- /manjaro
- /spring
- /diversity
- /lua
- /nodejs
- /julia
- /slackware
- /c
- /neovim