Click here to Skip to main content
       

C#

 
QuestionAccess to created control PinmemberKKW_acd17-Nov-12 6:18 
AnswerRe: Access to created control PinmentorDaveyM6917-Nov-12 8:30 
QuestionHow do you programatically open a file in c# to append? PinmemberXarzu17-Nov-12 2:05 
AnswerRe: How do you programatically open a file in c# to append? PinmentorDaveyM6917-Nov-12 2:35 
AnswerRe: How do you programatically open a file in c# to append? PinmemberEddy Vluggen17-Nov-12 10:32 
QuestionC# noob: Making Textbox entry a percentage, and Help with loops Pinmembermaul5916-Nov-12 19:46 
AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loops PinmvpRichard MacCutchan16-Nov-12 21:43 
AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loops PinmvpOriginalGriff16-Nov-12 22: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:
for (int day = 1; day <= days; day++)
   {
   ... calculate here
   }
 
So, my version would be:
   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 Pinmembermaul5916-Nov-12 23:20 
GeneralRe: C# noob: Making Textbox entry a percentage, and Help with loops PinmvpOriginalGriff16-Nov-12 23:26 
QuestionInterface issue when implementing Factory pattern PinmemberMichCl16-Nov-12 9:36 
AnswerRe: Interface issue when implementing Factory pattern PinmemberEddy Vluggen16-Nov-12 10:01 
GeneralRe: Interface issue when implementing Factory pattern PinmemberMichCl16-Nov-12 10:18 
GeneralRe: Interface issue when implementing Factory pattern PinmemberEddy Vluggen16-Nov-12 14:46 
GeneralRe: Interface issue when implementing Factory pattern PinmemberMichCl19-Nov-12 3:20 
AnswerRe: Interface issue when implementing Factory pattern PinmemberEddy Vluggen19-Nov-12 3:32 
GeneralRe: Interface issue when implementing Factory pattern PinmemberMichCl19-Nov-12 4:51 
GeneralRe: Interface issue when implementing Factory pattern PinmemberEddy Vluggen19-Nov-12 5:46 
GeneralRe: Interface issue when implementing Factory pattern PinmemberMichCl19-Nov-12 10:38 
GeneralRe: Interface issue when implementing Factory pattern PinmemberEddy Vluggen19-Nov-12 10:53 
QuestionIssue in accessing 32 bit C++ DLL in Windows Server 2008 PinmemberKumaran Poongavanam16-Nov-12 9:32 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 PinmemberEddy Vluggen16-Nov-12 10:04 
GeneralRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 PinmemberKumaran Poongavanam16-Nov-12 11:09 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 PinmvpDave Kreskowiak16-Nov-12 12:55 
AnswerRe: Issue in accessing 32 bit C++ DLL in Windows Server 2008 Pinmemberjschell17-Nov-12 7:11 

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

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


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 27 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid