GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Aug-2009, 15:00
ziorus ziorus is offline
Awaiting Email Confirmation
 
Join Date: Aug 2009
Posts: 11
ziorus is on a distinguished road

Cannot implicitly convert type 'int' to 'bool'


Hello all,

I am trying to redo a code in C# but I have a small mistake which I can't figure out. The error is: Cannot implicitly convert type 'int' to 'bool'. I do not have a bool which confuses me. The error occurs with the hasRemainder function at the if statements.

I have seen some good post in this forum with helpful people. I hope someone can give me the right direction to correct my mistake. Here is the code:

C-SHARP / C# Code:
 class Program
        
    {
        const double PIE = 3.14159;

        static void Main(string[] args)
        {
           
            int num = 5;
            Console.WriteLine
                ("The factorial of {0} is {1}.", num, factorial(num));
            double radius = 5;
            Console.WriteLine
                ("The area of a circle with radius {0} is {1}.", radius, area(radius));

            int a = 15;
            int b = 3;
            int c = 6;

           if (hasRemainder(a, b))
                Console.WriteLine
                    ("{0} / {1} has a remainder.", a, b);
            else
                Console.WriteLine
                    ("{0} / {1} does not have a remainder.", a, b);

            if (hasRemainder(a, c))
                Console.WriteLine
                    ("{0} / {1} has a remainder.", a, c);
            else
                Console.WriteLine
                    ("{0} / {1} does not have a remainder.", a, c);           
        }

        public static int factorial(int a)
        {
            int result = 1;
            for (int I = 2; I <= a; I++)
            {
                result *= I;
            }
            return result;
        }

        public static double area(double radius)
        {
            return PIE * radius * radius;
        }

        public static int hasRemainder (int a, int b)
        {
            return (a%b);
        }
    }

Many thanks for all that look and help...
Last edited by LuciWiz : 04-Aug-2009 at 15:41. Reason: Please insert your C# code between [c#] & [/c#] tags
  #2  
Old 04-Aug-2009, 15:02
ziorus ziorus is offline
Awaiting Email Confirmation
 
Join Date: Aug 2009
Posts: 11
ziorus is on a distinguished road

Re: little help with error


Wait... my return (a%b) is a bool return, isn't it???
  #3  
Old 04-Aug-2009, 15:12
ziorus ziorus is offline
Awaiting Email Confirmation
 
Join Date: Aug 2009
Posts: 11
ziorus is on a distinguished road

Re: little help with error


never mind... now I see my mistake...

if (hasRemainder(a, b) equal the bool from the function... rest of code...

coffee break....
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 12:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.