bull, I got a "bus error"

This is a discussion on bull, I got a "bus error" within the C Programming forums, part of the General Programming Boards category; this program is supposed to take in 2 numbers and then displays their product or sume, depending on what the ...

  1. #1
    jjj
    Guest

    bull, I got a "bus error"

    this program is supposed to take in 2 numbers and then displays their product or sume, depending on what the user selects.

    so check this code out please
    Code:
    #include <stdio.h>
    
    int main()
    { int num, num2, check, output;
     
      printf( "put in an integer by brother: " );
      scanf( "%d", &num );
      printf( "put in another and we either sum these two or multiply them soon:" );
      scanf( "%d", &num2 );
      
      printf( "do you want it multiplied or summed?  if you want it to be multiplied type in 1, if you want to divide type 2: " );
      scanf( "%d", check );
             
      if ( check == 1, output = num * num2 )
         printf( "%d", output);
      else if ( check == 2, output = num + num2 ) 
         printf( "%d", output);
      else printf( "you musta done something wrong" );
      return 0;
      }
    and by the way, what does a "bus error" usually imply if anthing at all? hmmm, time to search while I wait for help, but you can tell me something any book could so don't hesitate, I hope you tell me that is.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>scanf( "%d", check );
    You forgot the &. You need
    >>scanf( "%d", &check );

    [edit]
    >>if ( check == 1, output = num * num2 )
    What are you trying here?

    Code:
    if ( check == 1) 
    {
        output = num * num2;
        printf ("%d\n", output);
    }
    Last edited by Hammer; 09-12-2002 at 10:47 AM.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    jjj
    Guest
    oh, woops.

    oh, and use the braces on that if statement, i got it and that makes sense. sorry, it just didn't click, and I have done this before. thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange "syntax error" problem :S
    By Akkernight in forum C++ Programming
    Replies: 23
    Last Post: 02-23-2009, 04:22 AM
  2. "bus error"
    By Bnchs in forum C Programming
    Replies: 2
    Last Post: 05-14-2008, 05:32 PM
  3. help needed on debugging "bus error"
    By wuhua in forum C Programming
    Replies: 2
    Last Post: 05-18-2007, 04:15 PM
  4. I'm confused about "parse error"
    By Chizzlah in forum C++ Programming
    Replies: 12
    Last Post: 09-04-2002, 03:45 PM
  5. What the heck is a "syntax error"...?
    By face_master in forum C++ Programming
    Replies: 1
    Last Post: 08-28-2001, 07:06 AM

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