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 trialshawn khah
15,082 Pointsplease help me
Challenge Task 1 of 3
This final code challenge will require you to use almost everything we've covered in this course. You’ll write a program to celebrate completing this course by printing “Yay!” to the screen a given number of times. Write a program that: Prompts the user to enter the number of times to enter “Yay!”. I've done this for you. Leave this as it is. Prints “Yay!” to the screen that number of times (Hint: You’ll need a loop for this. You’ll also need to keep track of how many times the loop has run). You can print them all on the same line or on separate lines. Bummer! The prompt should print: Enter the number of times to print "Yay!": Preview Get Help Reset Code Recheck work Program.cs
1 using System; 2 3 namespace Treehouse.CodeChallenges 4 { 5 class Program 6 { 7 static void Main() 8 { 9 Console.Write("Enter number of times to enter Yay!"); 10 for(int i=0;i<input;i++) 11 { 12 Console.WriteLine("\"Yay!\""); 13 } 14 15 16 } 17 } 18 } 19
1 Answer
Kjetil Lorentzen
13,360 PointsHere's a solution that would work.
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 counter=0;
while (counter < total)
{
Console.WriteLine("Yay!");
counter ++ ;
}
}
}
}
william williams
2,912 Pointswilliam williams
2,912 Points