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 trialAhkeem Lang
16,358 PointsLast three challenges are tough..
I'm having a tough time answering these last three challenges... help please!
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
var callTotal = 0.0;
while (true)
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var entry = Console.ReadLine();
if (entry.ToLower = "Yay!")
{
break;
}
}
}
}
}
This is all I have so far
1 Answer
jason chan
31,009 Pointsnamespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
var count = 0;
Console.Write("Enter the number of times to print \"Yay!\": ");
var entry = Console.ReadLine();
try
{
var numberOfTimes = int.Parse(entry);
if(numberOfTimes > 0) {
while (count < numberOfTimes)
{
Console.WriteLine("Yay!");
count++;
}
} else {
Console.WriteLine("You must enter a positive number.");
}
}
catch(FormatException)
{
Console.WriteLine("You must enter a whole number.");
}
}
}
}
namespace is treehouse.codechallenges
start count at 0. prompt user to type number of times of saying yay. store variable entry try catch is if else
try(if) store variable int.Parse "integer becomes a number"; loop yay the number of times. Else(false) print "you have to enter a whole number."
If else nested is to test if it's positive. So if positive do loop. If not throw else print please give me positive number