Thread: strange error message

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    38

    strange error message

    im getting an error message in this simple program im practicing functions with that says "Command /Developer/usr/bin/g++-4.2 failed with exit code 1" and i have no idea whats causing it. heres my code:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int add (int a, int b, int c, int d, int e);
    int sub (int a, int b);
    int mult (int a, int b, int c, int d, int e);
    float divide (int c, int e);
    
    int main()
    {
    	
    	int a;
    	int b;
    	int c;
    	int d;
    	int e;
    	
    	cout<<"Please input 5 numbers. Press enter in between each number\n";
    	cin>>a;
    	cin.get();
    	cin>>b;
    	cin.get();
    	cin>>c;
    	cin.get();
    	cin>>d;
    	cin.get();
    	cin>>e;
    	cin.get();
    	
    	cout<<"Your 5 numbers were: "<<a<<", "<<b<<", "<<c<<", "<<d<<" and "<<e<<".\n\n";
    	cout<<"The sum of your numbers is: "<< add (a, b, c, d, e) <<".\n";
    	cout<<"The product of your numbers is: "<< mult (a, b, c, d, e) <<".\n";
    	cout<<"The difference of your first 2 numbers is: " <<sub (a, b) <<".\n";
    	cout<<"The quotient of your 3rd and 4th numbers is: "<< divide (c, e) <<".\n\n";
    	cin.get();
    }
    
    int add (int a, int b, int c, int d, int e)
    {
    	return a+b+c+d+e;
    }
    
    int sub (int a, int b)
    {
    	return a-b;
    }
    
    int mult (int a, int b, int c, int d, int e)
    {
    	return a*b*c*d*e;
    }
    
    float divide (int c, int e)
    {
    	return c/e;
    }

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    What IDE or command to compile are you using?
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    100
    You declare main() as returning an int. What exactly ARE you returning from main()?

  4. #4
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    It looks as though the compiler itself is producing the error message, not the program. I can't see anything wrong with the program itself. I use GCC and have never gotten an error from forgetting to return a value from main. But you should, so the OP should try that.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    38
    ah I think I figured it out. the program had a separate c file in it with a hello world program... who knows how that got there...

    i also have another problem with this code. I'm trying to make a do while loop so you can re-run the program however many times you want and it compiles perfectly but no matter what you type it loops instead of just looping if you press y. here it is

    Code:
    int main()
    {
    	int a;
    	int b;
    	float c;
    	int d;
    	float e;
    	char x;
    
    	do {
    	cout<<"please input your 5 numbers. press enter after each number\n";
    	cin>>a;
    	cin.get();
    	cin>>b;
    	cin.get();
    	cin>>c;
    	cin.get();
    	cin>>d;
    	cin.get();
    	cin>>e;
    
    	cout<<"\nThe sum of your numbers is: "<< add (a, b, c, d, e) <<".\n";
    	cout<<"The difference of your first two numbers is: "<< sub (a, b) <<".\n";
    	cout<<"The product of your numbers is: "<< mult (a, b, c, d, e) <<".\n";
    	cout<<"The quotient of your third and fifth numbers is: "<< divide (c, e) <<".\n\n";
    	cin.get();
    	cout<<"Would you like to analyze 5 more numbers? (y/n)\n";
    	cin>>x;
    	cout<<"\n";
    	} while (x = 'y');
    
    	if (x = 'n'){
    		return 0;
    	}
    
    	if (x != 'n' && x != 'y'){
    		cout<<"please input y for yes or n for no.\n";
    		cin>>x;
    	}
    }
    Last edited by dyelax; 06-24-2010 at 08:35 PM.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by rdrast View Post
    You declare main() as returning an int. What exactly ARE you returning from main()?
    Zero, implicitly, as specified by the C++ standard.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Code:
    while (x = 'y');
    Change that to:

    Code:
    while (x == 'y');
    Check the if-statement below that line, too.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Oct 2009
    Posts
    38
    sdjkla;;jfbslak;djf. I always screw that up. thank you nvoigt.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by dyelax View Post
    sdjkla;;jfbslak;djf. I always screw that up. thank you nvoigt.
    Then start writing conditions like it other way round

    Code:
    if( 'y' == x)

    and compiler will warn you if you pass = in place of ==
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Warn? Rather, it will spit out an error because a temporary is not an lvalue.
    GCC can also warn of you of this, I think, if you up the warning levels.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange behaviour of GCC
    By BlackOps in forum C Programming
    Replies: 14
    Last Post: 07-29-2009, 06:44 PM
  2. Need help with a strange for-loop problem
    By jasperleeabc in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2009, 08:47 AM
  3. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  4. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM