Error Message: "Cannot implicitly convert type int to bool"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdffit
    New Member
    • Apr 2017
    • 1

    Error Message: "Cannot implicitly convert type int to bool"

    "I am getting this error in the 2 for statements in the condition() on the words 'row' and 'column'. I am a novice and I don't understand how to fix this error."
    Code:
    	
    using System;
    				
    public class Program
    {
    	public static void Main()
    		
    	{
    		int number;     
                    int row;
    		int column;  
    		int width;
    
            Console.Write("Enter a number: ");
            number = Convert.ToInt32(Console.ReadLine());
    
            Console.Write("Enter the width: ");
            width = Convert.ToInt32(Console.ReadLine());
    
                for (row = 0; row; row++)
            {
                for (column = 0; column; column++)
                    Console.Write(number);
    
                    Console.WriteLine();
            }
    
    		
    	}
    }
    Last edited by Frinavale; Apr 10 '17, 08:32 PM.
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    The syntax should look more like this:
    Code:
    for (row = 0; row >= 10; row++)

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      The for loop syntax requires a stopping condition. That condition needs to evaluate to a true or false value.

      This is why Luk3r's suggestion works...because row>=10 evaluates to a true or false value.

      Comment

      Working...