Click here to Skip to main content
15,889,872 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm working on an assignment and the application has the user enter a phrase and number into two separate textboxes. This assignment uses c# in visual studio. Then, the phrase should appear in the listbox that number of times entered and each time the phrase appears, it should increase by one.
Example, phrase: Coding is fun.
Example number: 3
So the listbox would show
1. Coding is fun
2. Coding is fun
3. Coding is fun

Right now, nothing shows up in the listbox

What I have tried:

Here's the coding I have so far

string strPhrase = txtPhrase.Text;
double dblReptitions;
int intCounter = 1;



if (double.TryParse(txtReptitions.Text, out dblReptitions))
{
for (intCounter = 1; intCounter == dblReptitions; intCounter ++)
{

lstPhrase.Items.Add(strPhrase);

}
Posted
Updated 19-Nov-18 10:02am

1 solution

Look at your code:
for (intCounter = 1; intCounter == dblReptitions; intCounter ++)
It will only execute the loop when intCounter exactly equals dblReptitions - s to do anything, you must ask for one repitition.

Try:
for (intCounter = 1; intCounter < dblReptitions; intCounter ++)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900