Click here to Skip to main content
15,886,067 members
Home / Discussions / C#
   

C#

 
QuestionAccess to created control Pin
KKW_acd17-Nov-12 5:18
KKW_acd17-Nov-12 5:18 
AnswerRe: Access to created control Pin
DaveyM6917-Nov-12 7:30
professionalDaveyM6917-Nov-12 7:30 
QuestionHow do you programatically open a file in c# to append? Pin
Xarzu17-Nov-12 1:05
Xarzu17-Nov-12 1:05 
AnswerRe: How do you programatically open a file in c# to append? Pin
DaveyM6917-Nov-12 1:35
professionalDaveyM6917-Nov-12 1:35 
AnswerRe: How do you programatically open a file in c# to append? Pin
Eddy Vluggen17-Nov-12 9:32
professionalEddy Vluggen17-Nov-12 9:32 
QuestionC# noob: Making Textbox entry a percentage, and Help with loops Pin
maul5916-Nov-12 18:46
maul5916-Nov-12 18:46 
AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loops Pin
Richard MacCutchan16-Nov-12 20:43
mveRichard MacCutchan16-Nov-12 20:43 
AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loops Pin
OriginalGriff16-Nov-12 21:40
mveOriginalGriff16-Nov-12 21:40 
There are a couple of simple things to do - firstly as Richard said, you need to use floating point values instead of integers:
2 + 30% is 2.6, but as an integer it is 2 again! Laugh | :laugh:

The second is that you are looping through the days, so you don't need to include the number of days in each calculation - just use the result from the previous day.

The third is that when you want an increased value, you can't just multiply by the percentage - 2 * 30% is 0.6, so your increase is 0.6, not your population. To increase your population, multiply but 1.0 + the percentage.

Finally, there is a better way to loop through the days: use a for loop instead of a while:
C#
for (int day = 1; day <= days; day++)
   {
   ... calculate here
   }


So, my version would be:
C#
resultsListbox.Items.Add(string.Format("The population for day {0} is {1}", day, organisms));
organisms *= 1.0 + percent;
with percent adjusted to 0.3 as Richard suggested.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

GeneralRe: C# noob: Making Textbox entry a percentage, and Help with loops Pin
maul5916-Nov-12 22:20
maul5916-Nov-12 22:20 
GeneralRe: C# noob: Making Textbox entry a percentage, and Help with loops Pin
OriginalGriff16-Nov-12 22:26
mveOriginalGriff16-Nov-12 22:26 
QuestionInterface issue when implementing Factory pattern Pin
MichCl16-Nov-12 8:36
MichCl16-Nov-12 8:36 
AnswerRe: Interface issue when implementing Factory pattern Pin
Eddy Vluggen16-Nov-12 9:01
professionalEddy Vluggen16-Nov-12 9:01 
GeneralRe: Interface issue when implementing Factory pattern Pin
MichCl16-Nov-12 9:18
MichCl16-Nov-12 9:18 
GeneralRe: Interface issue when implementing Factory pattern Pin
Eddy Vluggen16-Nov-12 13:46
professionalEddy Vluggen16-Nov-12 13:46 
GeneralRe: Interface issue when implementing Factory pattern Pin
MichCl19-Nov-12 2:20
MichCl19-Nov-12 2:20 
AnswerRe: Interface issue when implementing Factory pattern Pin
Eddy Vluggen19-Nov-12 2:32
professionalEddy Vluggen19-Nov-12 2:32 
GeneralRe: Interface issue when implementing Factory pattern Pin
MichCl19-Nov-12 3:51
MichCl19-Nov-12 3:51 
GeneralRe: Interface issue when implementing Factory pattern Pin
Eddy Vluggen19-Nov-12 4:46
professionalEddy Vluggen19-Nov-12 4:46 
GeneralRe: Interface issue when implementing Factory pattern Pin
MichCl19-Nov-12 9:38
MichCl19-Nov-12 9:38 
GeneralRe: Interface issue when implementing Factory pattern Pin
Eddy Vluggen19-Nov-12 9:53
professionalEddy Vluggen19-Nov-12 9:53 
QuestionIssue in accessing 32 bit C++ DLL in Windows Server 2008 Pin
Kumaran Poongavanam16-Nov-12 8:32
Kumaran Poongavanam16-Nov-12 8:32 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 Pin
Eddy Vluggen16-Nov-12 9:04
professionalEddy Vluggen16-Nov-12 9:04 
GeneralRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 Pin
Kumaran Poongavanam16-Nov-12 10:09
Kumaran Poongavanam16-Nov-12 10:09 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 Pin
Dave Kreskowiak16-Nov-12 11:55
mveDave Kreskowiak16-Nov-12 11:55 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 Pin
jschell17-Nov-12 6:11
jschell17-Nov-12 6:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.