|
try to make a vector line
|
|
|
|
|
Just use VG.net[^]!
A little bit of advertising for ya, Frank
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
I am almost done with a project to calculate employee salaries, but am having problems adding a 5% bonus on everyone's final salary. The salary variable is in integer format and I need to convert it to a double. is there a quick and easy way to fix this issue? I am getting the data type error in the Everbody's bonus section. Below is the code ( this is my first program ever, so it is most likely very sloppy, sorry in advance!):
using System;
namespace EmployeeSalary
{
/// <summary>
/// Calculates employee salary based on experience, birthday, position, and company success
/// </summary>
class EmployeeSalary
{
[STAThread]
static void Main(string[] args)
{
int executive, //employee's executive status
finalSalary = 0, //employee's final salary
baseSalary = 5000, //employee's base salary
experience, //employee's years of experience
birthday; //employee's birthday bonus
// Employee's executive status (1 = exec, 2 = not exec)
Console.Write( "Please enter executive code (1/yes 2/no): " );
executive = Int32.Parse( Console.ReadLine() );
if ( executive == 1 )
{
Console.WriteLine( "\nSorry, you're an executive, no benefits for you!" );
goto finalWrite;
}
//Employee's years of experience (1 = less than 3 yrs, 2 = 3 to 5 yrs, 3 = over 5 yrs)
Console.WriteLine( "\nPlease enter your experience code (1/less than 3 yrs, 2/3-5 yrs, 3/over 5 yrs)" );
experience = Int32.Parse( Console.ReadLine() );
if ( experience == 1 ) finalSalary = baseSalary - 2000;
else if ( experience == 2 )
{
finalSalary = baseSalary + 2500;
goto bonusAdd;
}
else if ( experience == 3 )
{
finalSalary = baseSalary + baseSalary;
goto bonusAdd;
}
else
{
Console.WriteLine("That is not a valid entry");
goto bonusAdd;
}
//Employee birthday question
Console.WriteLine( "\nIs this month your birthday (1/yes 2/no)?" );
birthday = Int32.Parse(Console.ReadLine() );
if ( birthday == 1)
{
finalSalary = finalSalary + 250;
goto bonusAdd;
}
if ( birthday == 2) goto bonusAdd;
//Everybody's bonus
bonusAdd:
finalSalary = finalSalary + (finalSalary * 0.5);
//Write final salary
finalWrite:
Console.Write("Your salary for this month is: ");
Console.WriteLine(finalSalary.ToString("c"));
}
}
}
|
|
|
|
|
ivelander wrote: if ( executive == 1 )
{
Console.WriteLine( "\nSorry, you're an executive, no benefits for you!" );
goto finalWrite;
}
You wrote this in order to pass any non-1 chars, this is wrong, because any one may enter 0 for example or any string, you must check the input.
While you have done this in the second input :
ivelander wrote: else
{
Console.WriteLine("That is not a valid entry");
goto bonusAdd;
}
You may do this :
ivelander wrote: finalSalary = finalSalary + 250;
Like this:
finalSalary+=250;
And at last :
ivelander wrote: finalSalary = finalSalary + (finalSalary * 0.5);
double lastResult = Convert.ToDouble(finalSalary);
lastResult += lastResult*0.5;
Hope this helps.
"Praying." Is this only what I can do for him ?
|
|
|
|
|
> I am almost done with a project to calculate employee salaries, but am having problems adding a 5% bonus on everyone's final salary.
Hmm, I've worked at companies that had this very same problem.
Here is an easy way to add 5% to an integer value:
int AddFivePercent( int value )
{
return (105 * value) / 100;
}
Of course, you might want to make a more general case function like AddXPercent(), but I'll leave that as an exercise.
And there is also the option of converting to float, as you mentioned.
Matt Gerrans
|
|
|
|
|
By the way, if you are just starting out, you should know that using goto is a very bad habit -- not one you want to develop.
Matt Gerrans
|
|
|
|
|
I only used it 6 times in less that 100 lines of code... not bad. Haha. Thanks for all the advice, the good news is that things can only get better from here. I'm sure I will be back for more help.
|
|
|
|
|
If you are interested to see how it would be done without any goto s post back. Even better, try doing it yourself without any goto s and if you have in trouble in the process, post your questions here again. After you have it in the goto -free state, you can decide for yourself whether the code seems better.
(Actually, with a small example like this, it will not be clearly better, but I've seen very large pieces of production code that use goto s and that becomes hideously incomprehensible and hard to maintain).
Matt Gerrans
|
|
|
|
|
Need to build a two dimensional math graph.Anybody can give me any ideas about how to do it?
|
|
|
|
|
I have this graphic, that I want to move up and down the form by the user clicking on one button to go up and one button to go down, it sounds like a game, but it really isn't. I have no idea on how to make or even start on this project, can it be done with C#.Net? and do I use DirectX? or the Drawing Class?
|
|
|
|
|
<code
private void="" btnmove_click(object="" sender,="" system.eventargs="" e)
="" {
="" this.location="new" point(this.location.x="" ,="" this.location.y="" -50);
="" which="" moves="" current="" form="" 50="" pix="" up="" and="" so="" on="" ..=""
="" }
="">
I hope this works.
|
|
|
|
|
How are you planning to display the graphic? Through a standard PictureBox control? Or are you going to draw it yourself?
Either case, you need to track the current position of the graphic using a variable and update the position in the button click.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
It is actually am Image, so I guess a picture box control.
|
|
|
|
|
Then it becomes fairly simple. Just change the Top/Left properties of the PictureBoxControl and you're done.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
I want to make Tablet PC application using C#.
I was serching on google and found that I need to "add reference" (in Solution Explorer) . And then Need to add the reference of "Microsoft Tablet PC API" as a component name but I am not able to find that. What should I do?
Thanks
I would appreciate if you could check this on the platform.
Thanks in advance
Preeti9
|
|
|
|
|
Hi,
My C# / Winform program talks to a COM (OLe Aotomation) server. I need
to pass the handlw of a combobox to the COM server and the server will
populate the combobox by sending CB_ADDSTRING message. The result is: the
combobox got populated but when I dropdowm (the combobox is DROOPDOWNLIST
style) I got very narrow dropdown part with a tiny scroll bar, and if I
select an item I got a System.ArgumentOutOfRangeException. In code just
after the server populated the combobox I can see that MyCombobox.Items.Count is 0. We know in C# .NET code we add string to combobox this way: MyCombobox.Items.Add("abc"). It seems if we use the
CB_ADDSTRING to add strings to a .NET combobox the Items is empty.
Any one got the similar problem?
Thanks in advance for any help.
Bogang Tian
|
|
|
|
|
Windows Controls are not thread safe.Any
attemp to play with them in external code may result to undesirable results such as yours.
If you can return that string (for example via an event in that activex) to your code this
whould do the job.
<br />
private delegate void AddTextDelegate(String strText); <br />
private void AddText(String strText) <br />
{ <br />
MyComboBox.Items.Add(strText); <br />
} <br />
and in your event handler:
<br />
Invoke(new AddTextDelegate(AddText), <br />
new Object[] { strText});<br />
I hope this works.
|
|
|
|
|
Thanks for your help.
That "COM server" is only an OLE Automation server. It does not fire any
event. Only thing it offers is a member function that takes an int as
the handle of the combobox, and populate the combobox by sending CB_***
messages.
I am curious: after calling the COM server member function I can see
the combobox is populated with data. Where are these data stored? Any
way to get them and put them them into the Items collection?
Thanks again.
Bogang Tian
|
|
|
|
|
Hello everyone!
OK, I have a program that has to find files inside of some specific directories and then add the filenames to a string array. There's like 18,000 files... My problem: The last line on the file comes cut out. I thought this was some file limit problem, so I broke it down into 2 files. Still the problem persisted. Then I went for 4. Still. Then I went to 6. STILL! Anyone know what's wrong here? The files are on a network drive, but I don't think that's it, since I've seen this problem a long time ago on regular drives. Anyone know how to fix it? Thanks!
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Are you calling Flush and/or Close on the stream when you are finished?
|
|
|
|
|
|
"It worked!" ?
This seems funny to me, because it implies that closing a file after writing to it is some kind of clever trick or technique as opposed to what you should always do.
BTW, this sounds like something you might want to do with a script (Python or Ruby, or (if you must) Perl, etc.).
Matt Gerrans
-- modified at 22:03 Friday 21st October, 2005
|
|
|
|
|
|
I have a .bmp file and I need to do it SplashScreen for my form.Anybody can tell me how to do it?
|
|
|
|
|
hi there,
I'm pretty sure that there are a lot of articles about this on CP site.
below is just one of them
Splash Screen
Hope this helps
<< >>
|
|
|
|