Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRadosław Kwiatkowski
5,300 Points1/3 Code Challenge C# Basic
Hi, my code doesnt work. Getting error
error CS0029: Cannot implicitly convert type int' to
bool'
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() {
Console.Write("Enter the number of times to print \"Yay!\": ");
//var total = int.Parse(Console.ReadLine());
int userInput = Convert.ToInt32(Console.ReadLine());
for (int i = 0;i = userInput;i++)
{
Console.WriteLine("Yay!");
}
}
}
}
2 Answers
Steven Stanton
59,998 PointsHi Radoslaw,
I think the problem seems to be the second clause in your for statement -
You have
i = userinput;
which is an instruction to assign userInput to the variable i.
What you need instead is a condition - e.g.
i < userInput;
(which will return true or false - which is why the error mentions bool).
So your full for statement would read as
for (int i = 0;i < userInput;i++)
{
Console.WriteLine("Yay!");
}`
Hope that makes sense.
Radosław Kwiatkowski
5,300 PointsThanks for you assistance. I thought the problem is Convert.ToInt method - error line was pointing to it.
Roberto Tsvetanov
846 PointsRoberto Tsvetanov
846 PointsHey, your problem is in the For Loop.
for( int i = 0 ( here u say from where to start) ; i < userInput (here you say where to end) ; i++ ( here you increment the i variable with 1 everytime). )
You can't compare bool statement with just a variable.
Try it this way :
for (int i = 0;i < userInput;i++) { Console.WriteLine("Yay!"); }