2 Replies - 1312 Views - Last Post: 09 September 2008 - 08:23 PM Rate Topic: -----

#1 dundugadu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-September 08

Code compiles fine, however I get Bus error (core dumped) when ran

Post icon  Posted 09 September 2008 - 07:55 PM

 #include <iostream>
using namespace std;

int main()
{
  int grade[4];
  int average;
  cout << "please enter four numeric grades to get the average.\n\n";
  cin >> grade[0] >> endl;
  cin >> grade[1] >> endl;
  cin >> grade[2] >> endl;
  cin >> grade[3] >> endl;
  average = (grade [0] + grade[1] + grade[2] + grade[3]) / 4;
  cout << average << " is your average grade.";
  return 0;
} 




For some reason I don't get any compiler errors but when I run the program I get the error "Bus error (core dumped)" after I enter the second number into the program and press enter. I am not sure what is wrong with my code. I don't see any syntax errors and I don't believe I have misused the array either.

Is This A Good Question/Topic? 0
  • +

Replies To: Code compiles fine, however I get Bus error (core dumped) when ran

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Code compiles fine, however I get Bus error (core dumped) when ran

Posted 09 September 2008 - 08:18 PM

Get rid of the endls at the end of your input calls.
Was This Post Helpful? 0
  • +
  • -

#3 fountainoftruth   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 04-December 07

Re: Code compiles fine, however I get Bus error (core dumped) when ran

Posted 09 September 2008 - 08:23 PM

endl = end line

Basically, you shouldn't have it with your cins at all. At the end of your cout statements would be fine, though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1