When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
33 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
#include<iostream>
#include<cmath>
using namespace std;
int main(){
float income; cin >> income;
float tax,tax1, tax2, tax3 ;
if (income <= 180000) tax = 0;
if (income <= 500000)
tax2 = (income - 180000) * 0.1;
if(income <= 800000)
tax2 = (income - 500000) * 0.2 + 32000;
else tax3 = (income - 800000)* 0.3 + 92000;
cout<< tax << ": "<< tax1 << ": "<< tax2 << ": "<< tax3 << endl;
}
I reccomend stepping trough your code with a debugger
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
float income;
cin >> income;
float tax, tax1, tax2, tax3;
if (income <= 180000)
tax = 0;
if (income <= 500000)
tax2 = (income - 180000) * 0.1;
if (income <= 800000)
tax2 = (income - 500000) * 0.2 + 32000;
else
tax3 = (income - 800000) * 0.3 + 92000;
cout << tax << ": " << tax1 << ": " << tax2 << ": " << tax3 << endl;
}
```Requested by: dragonslayer0531
don't follow the conditions/code, i have just changed it a bit
also, format your code ๐
it's just when I enter 50000 the result is
0: 1.64886e-37: -58000: 2.23592e-37
and i'm confused here why the tax2 is like that?
and there's also this ambiguity, that if tax3 condition isn't even reaching how does tax3 somehow get printed
no no, there's no error
if there is no error, what is your question
i just want to know how is tax3 somehow getting calculated if it's an else
step through with a debugger and find out why the else is executed
yes, use a debugger to see whats happening :)
isn't that statement disregarded for 50000
check with a debugger
and see if it actually happens as you expect
also check any warnings you might have
but, you are not understanding. what debugger do you use tho lol
if you have an ide the one build in
and it's just a general code which I have changed a bit to see what's happening in other case
https://www.learncpp.com/cpp-tutorial/the-debugging-process/
learn cpp.com goes into how to use a debugger
like we can see if we put 50000 the value should be integer in first 3 cases but it's of some e power here
it's an insanely usefull tool
yeah and a debugger will let you see exactly what and why things happen
oh
Please, use a debugger. It will let you walk through your code, step by step, learn see what's happening. What branches are being taken, what values things are being set to, etc
are yaar. that's not, ok leave it for now