Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.25/5 (4 votes)
See more:
C#
using System;

namespace Ordendenumeros
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string numero1texto, numero2texto;
			int numero1, numero2; 
			do
			{
				Console.WriteLine ("Escriba 5 numeros(en columna): ");
				numero1texto = Console.ReadLine ();
				numero2texto = Console.ReadLine ();
			

				numero1 = Convert.ToInt32(numero1texto);
				numero2 = Convert.ToInt32(numero2texto);
				

				switch(numero1)
				{
				case(numero1>numero2):
					Console.WriteLine(numero1texto, numero2texto);
				break;

				case(numero1<numero2):>
					Console.WriteLine(numero2texto, numero1texto);
				break;

				}
			

			}while(true);

		}
	}
}


Error: "Cannot implicitly convert type 'bool' to 'int'
help?
Posted
Updated 4-Dec-14 5:52am
v2
Comments
Maciej Los 4-Dec-14 11:54am    
In which line error occurs?

The selector case(numero1>numero2): is invalid. The switch statement can only compare numero1 with other ints. The expression (numero1 > numero2) is of type bool.

It seems you need to read up on C# basics.

/ravi
 
Share this answer
 
Comments
Maciej Los 4-Dec-14 12:10pm    
5ed!
Ravi Bhavnani 4-Dec-14 12:14pm    
Thank you, sir!

/ravi
Sergey Alexandrovich Kryukov 4-Dec-14 17:42pm    
Sure, a 5.
—SA
Ravi Bhavnani 4-Dec-14 18:23pm    
Thanks, SA!

/ravi
BillWoodruff 4-Dec-14 19:19pm    
+5
your switch case is having integer value, while your case is returning true/false. That is why it is saying can not convert bool to int. Keep switch variable and case variable of same type.
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 5-Dec-14 1:14am    
Why my answer got devoted??
Using the following code :

C#
using System;

namespace ConsoleApplication8
{
    class MainClass
    {
        public static void Main(string[] args)
		{
			string numero1texto, numero2texto;
			int numero1, numero2; 
			do
			{
				Console.WriteLine ("Escriba 5 numeros(en columna): ");

				numero1texto = Console.ReadLine ();
				numero2texto = Console.ReadLine ();

				numero1 = Convert.ToInt32(numero1texto);
				numero2 = Convert.ToInt32(numero2texto);

			    int b = numero1 > numero2 ? numero1 : numero2;
			    Console.WriteLine(b + "  Is Bag ");
 
			}while(true);
 
		}
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900