error cl.exe???

This is a discussion on error cl.exe??? within the C++ Programming forums, part of the General Programming Boards category; What is this error?...this program is not working properly Code: #include <iostream> using namespace::std; int binary (int num); int main() ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    error cl.exe?

    What is this error?...this program is not working properly
    Code:
    #include <iostream>
    using namespace::std;
    
    int binary (int num);
    
    
    int main()
    {
    	int n;
    	cout << "number: " << endl;
    	cin >> n;
    	binary(n);
    	cout << n << endl;
    	return 0;
    }
    
    int binary (int numb)
    {
    	int number=0;
    	int n;
    	//int nu;				
    
    	n = numb % 2;	
    	n = number;
    	cout << n << endl;
    	
    	if (numb == 0)			
    	{
    		return 0;
    	}
    	else 
    	{
    		return binary(numb / 2);	 
    	}
    }

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    error cl.exe???

    ***I know that this is posted twice...I have tried to delete the other one, but the system will not let me***
    What is this error?...this program is not working properly


    Code:
    #include <iostream>
    using namespace::std;
    
    int binary (int num);
    
    
    int main()
    {
    	int n;
    	cout << "number: " << endl;
    	cin >> n;
    	binary(n);
    	cout << n << endl;
    	return 0;
    }
    
    int binary (int numb)
    {
    	int number=0;
    	int n;
    	//int nu;				
    
    	n = numb % 2;	
    	n = number;
    	cout << n << endl;
    	
    	if (numb == 0)			
    	{
    		return 0;
    	}
    	else 
    	{
    		return binary(numb / 2);	 
    	}
    }
    Last edited by student2005; 03-11-2004 at 08:48 AM.

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    your function is designed to return something and it does their is nothing in your main to get what it returns though

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    I think cl.exe is the compiler for Visual C++.

    Your program compiles fine on Dev-C++. (however, I don't think it runs the way you expect).

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> ...this program is not working properly

    Try do be more discriptive. Phrases like that and 'error cl.exe' don't mean a thing. State what you want the program to do, and what the errors you are having are.

    Code:
    n = numb % 2;	
    n = number;
    cout << n << endl;
    Why do you assign 'n' a value and then immediately overwrite it?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    thanks

    got any ideas on how to fix this one?

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    try replacing
    using namespace::std;
    with
    using namespace std;

    even if you did get it to work, it would always output:

    number:
    123 (user input)
    0
    (some number)

    your problem is in the function:
    Code:
    int binary (int numb)
    {
    	int number=0; //what was this for?
    	int n;
    	//int nu;				
    
    	n = numb % 2; //what is the math for in the first place?
    	n = number; //the math was just overwritten by a zero
    	cout << n << endl;  //it outputs the zero
    	
    	if (numb == 0)			
    	{
    		return 0;
    	}
    	else
    	{
    		return binary(numb / 2);	 
    	}
    }
    Last edited by major_small; 03-11-2004 at 09:40 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    If it looks odd, its because the cross-post has been merged.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    27
    int number=0; //was me trying out something

    the math is to convert a decimal # (user input) to a binary #

    I have to write a program that converts a decimal # (user input) to a binary #, octal, and hex

    n= number; /just a mistake

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    recursive functions only really work if you have the function use it's own return... in this case, it's not worth it... the returned number is just thrown out the window on the way back... you'd be better off using a loop within a function... this would be a valid recursive funtion:
    Code:
    double power(int base,int exp)
    {
       if(exp==0)
          return 1;
       else if(exp>1)
          return (power(base,exp-1)*base)
       else
          return base;
    }
    your code is working, it's just outputting the binary backwards
    Last edited by major_small; 03-11-2004 at 10:20 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    Qui
    Qui is offline
    Registered User
    Join Date
    May 2003
    Posts
    30
    perhaps this is more along the lines of what you are looking for.

    Code:
    	int number = numb;
    	int n[20];
    	int i =0;
    	//int nu;				
    	n = numb;	
    	do
    	{	
    		n[i]=number%2;
    		number /= 2;
    		i++;
    	}while(number != 0);
    	do{
    		cout<<n[i];
    		i--;
    	}while(i !=0);

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21