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!

Zach
  • 61
  • 7
  • 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. – Andrew May 03 '18 at 05:24
  • 1
    while (count != 10) ; <<< you put semi-colon after your while it will cause you like you while (count != 10) { } – Asakuraa Ranger May 03 '18 at 05:25
  • 1
    I call shenanigans – TheGeneral May 03 '18 at 05: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. – Andrew May 03 '18 at 05: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 – Zach May 03 '18 at 05:28
  • For further reading about this `;`, have a look at [why there is semicolon after loop while();](https://stackoverflow.com/questions/22155233/why-there-is-semicolon-after-loop-while) – mmushtaq May 03 '18 at 05:32

2 Answers2

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();
    }
Pieter Alberts
  • 829
  • 1
  • 7
  • 23
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;
}
Norbert Forgacs
  • 605
  • 1
  • 8
  • 27