
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

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

Thought it might be worth having a dedicated thread for standing desk treadmills (for those interested, here’s our general thread on stan...
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

Just been adding some more portals, currently have the following languages:
Apache Groovy
C
C#
C++
Clojure
CoffeeScript
Crystal ...
New

Do you like to help others on stackoverflow in your free time? And what’s your reputation on Stackoverflow? :smirk::joy::rofl:
New

I just switched jobs to tech lead with a small team of about 6 other developer. This is my first tech lead job. What do I need to know? A...
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

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

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

I’m working on a Spring Boot project and I have a controller where I want to map multiple request paths to a single method. Let’s say I h...
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

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

I’ve been really enjoying obsidian.md:
It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New

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

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New

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

Author Spotlight
James Stanier
@jstanier
James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New

The File System Access API with Origin Private File System.
WebKit supports new API that makes it possible for web apps to create, open,...
New

The overengineered Solution to my Pigeon Problem.
TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
New
Categories:
Sub Categories:
- All
- In The News (10165)
- Dev Chat
- Questions (32)
- Resources (118)
- Blogs/Talks (26)
- Jobs (3)
- Events (15)
- Code Editors (58)
- Hardware (57)
- Reviews (5)
- 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
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /ocaml
- /react
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /html
- /deepseek
- /zig
- /scala
- /sublime-text
- /textmate
- /lisp
- /debian
- /nixos
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /django
- /ubuntu
- /revery
- /manjaro
- /spring
- /nodejs
- /diversity
- /lua
- /slackware
- /julia
- /c
- /neovim