Game Warden Forums

Go Back   Game Warden Forums > Game Warden > General Discussion

General Discussion You can talk about anything here. Not moderated. Post exploits, complaints, questions, off topic etc. Open 24 hours a day....

Search Box


Mini Stats
Members 7,463 Entries 0
Members Entries
Threads 6,666 Reviews 0
Threads Reviews
Posts 116,439 Polls 77
Posts Polls
Content 4 Files 79
Content Files
Links 10 Ads 0
Links Ads
More...
Latest Poll
SoL: Which multiplayer mode are you interested in most?
This poll is closed
Classic deathmatch 3 5%
Team deathmatch 8 13%
Coop missions 31 51%
Special missions (CTF, KotH,...) 8 13%
None - I will only play the singleplayer campaign 11 18%
Voters: 61 100%
Replies (24)
Hot Downloads
Derelict
Posted By: MatthewPapa
Posted On: 08-09-2009
Replies: 1
Views: 3,784
Freespace 2 Open Installer
Posted By: MatthewPapa
Posted On: 08-16-2009
Replies: 2
Views: 5,582
Sol system skybox
Posted By: shiv
Posted On: 08-23-2009
Replies: 1
Views: 5,976
TSJ Amaterasu
Posted By: shiv
Posted On: 08-22-2009
Replies: 0
Views: 5,990
GVJ Khonsu
Posted By: shiv
Posted On: 08-22-2009
Replies: 0
Views: 5,872
More...
Old 11-02-2005   #1
Gai Daigoji
Gekigangar!
 
Gai Daigoji's Avatar
 
Join Date: Feb 2005
Location: UK
Posts: 171
Help with a small program

Ok I am dabbling with learning C# and want to make a program were I can calculate income tax. Here's what I got so far:

using System;

class CalculateTaxalculate
{
static void Main()
{
string inputSalary;
double TaxNumber;
double TaxSum;
double Salary;

Console.WriteLine("Please enter Salary");
Salary = Console.Read();
inputSalary = Convert.ToInt32(Salary);

if (Salary > 23000)
{
TaxSum = Salary * 0.22;
Console.WriteLine("Your tax is ");
Console.Read(TaxSum);
}

if (Salary == 23000)
{
TaxSum = Salary * 0.22;
Console.WriteLine("Your tax is ");
Console.Read(TaxSum);
}


else if (Salary < 23000)
{
TaxSum = Salary * 0.10;
Console.Write("Your Tax is ");
Console.Read(TaxSum);
}



else if (Salary > 32000)
{
TaxSum = Salary * 0.40;
Console.Write("Your Tax is ");
Console.Read(TaxSum);
}

if (Salary < 0)
{
Console.WriteLine("Invalid number, please try again");
}

if (Salary > 100000)
{
Console.WriteLine("Invalid number, please try again");
}




Can anyone tell me whats wrong with this or what I need to have? Many thanks
__________________
Project Leader / FREDer: Project: Gundam Seed: Wheels of Destiny -Forum
Gai Daigoji is offline   Reply With Quote
Old 11-02-2005   #2
karajorma
He is watching YOU
 
karajorma's Avatar
 
Join Date: Dec 2004
Posts: 5,204
Is it not compiling or is it giving you the wrong answers?

I've not worked through the logic much but remember that else always associates with the nearest if (at least in Java it does. I don't know much about C# except that it's MS's attempt to make Java so I'd imagine it is the same in that respect). I can see that screwing things up cause you've got a lot of else if's in there.
karajorma is offline   Reply With Quote
Old 11-12-2005   #3
kode
The Swede
 
kode's Avatar
 
Join Date: Apr 2005
Location: Sweden
Posts: 73
if you still need help...

well anyway, I don't code C#, but I'd suggest you either nest all those if-statements together, or use a switch case with cleverer partitioning of the options. as it is now, I suppose that given a salary larger than 32000, it would calculate and print the tax for both >23000 and >32000 - this is because the if statements aren't nested together.

also, I have a question regarding this:
Code:


TaxSum = Salary * 0.10;
Console.Write("Your Tax is ");
Console.Read(TaxSum);



doesn't the last line expect the user to enter data? If I understand it correctly, you just calculated the tax and saved it to the variable TaxSum, then printed out in the console the line "Your tax is: "
and then ask the user for input overwriting the same variable in which you saved the taxsum. Again, I don't code C#, but if it is the case that you want to output stuff, I think Console.Write would be the right method to use.
__________________
kode is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 08:28 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2004-2009 Game Warden