0

running into more issues as I run along. I looked around for a few minutes through the forum this time for an answer for this and didn't successfully find anything (I mean most of it contains more complex ways of doing their while loops so I didn't know what to exactly expect.) Here is the c# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodingExcercise
{
class Program
{
    static void Main(string[] args)
    {
        int answer;
        int number;
        Console.WriteLine("Type in the number you desire the multiplication table for!");
        number = Convert.ToInt32(Console.ReadLine());
        int count = 1;
        while (count != 10) ;
       answer = number * count;
        Console.WriteLine("{0}*{1}={2}", number, count, answer);
        count = count + 1;
    }
}
}

Thats all of it (I'm mainly just running through basic exercises for doing these operations) I'm trying to post a numbers multiples up to ten.

and also tbh I get a faster reply here then looking through all the closed threads until I find the correct one, sorry if there is already one like this. Thanks!

6
  • 6
    Your while (count != 10) ; is an infinite loop. It will execute ; forever. You need to put the code you want to repeat between { }. If there are no brackets, only the next statement is considered, and ; is an empty statement. Commented May 3, 2018 at 5:24
  • 1
    while (count != 10) ; <<< you put semi-colon after your while it will cause you like you while (count != 10) { } Commented May 3, 2018 at 5:25
  • 1
    I call shenanigans Commented May 3, 2018 at 5:26
  • 1
    Furthermore, if you want your code to run just 10 times, that's a typical case for a for loop instead. Oh, and indent your code properly, so it's clear where each block starts and ends. Finally, better use count++ to increment a variable. Commented May 3, 2018 at 5:27
  • Yeah I notice the two problems now, I forgot that semicolons dont go after certain things. I also totally forgot about the { } Thanks a lot :D Commented May 3, 2018 at 5:28

2 Answers 2

2

Try using this:

 static void Main(string[] args)
    {
        int answer;
        int number;
        Console.WriteLine("Type in the number you desire the multiplication table for!");
        number = Convert.ToInt32(Console.ReadLine());
        int count = 1;
        while (count != 10)
        {
            answer = number * count;
            Console.WriteLine("{0}*{1}={2}", number, count, answer);
            count = count + 1;
        }
        Console.ReadLine();
    }
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you miss typed ';' after the while loop. Replace your while loop with this:

while (count != 10) 
{
   answer = number * count;
   Console.WriteLine("{0}*{1}={2}", number, count, answer);
   count = count + 1;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.