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 trial

C# C# Basics (Retired) Perfect Final

Anusha Singh
PLUS
Anusha Singh
Courses Plus Student 22,106 Points

I do not know how to do this challenge. I tried doing this but the warning said -" cannot implicitly convert string int"

The question is to print "yay!" and the user is asked how many ties should we print "yay!"

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            string number = Console.ReadLine();
            int number1 = int.Parse(number);
            int numberone = 0;

            bool cycle = true;
            while (cycle == true) {
                Console.WriteLine("Yay!");
                numberone = number + 1; 
                if (numberone > number1) {
                     break;
                }
            }

        }
    }
}
Anusha Singh
Anusha Singh
Courses Plus Student 22,106 Points

here is the question - 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.

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi Soma Singh you're getting the "cannot implicitly convert string int" error because of this line

numberone = number + 1; 

The correct variable to be used for the calculation in your program is supposed to be number1. number is a string, not an integer.

Once this mistake is fixed, you won't be getting the implicit conversion error anymore, however, you still need to make some adjustment to the while loop in order to pass the challenge.

happy coding.

Anusha Singh
Anusha Singh
Courses Plus Student 22,106 Points

Hi William Li, thanks for finding a solution for my query.

michaelcodes
michaelcodes
5,604 Points

I just logged in and saw this question now, I am glad that William Li was able to help :) If you have any more questions don't hesitate to ask! Take care and happy coding!