Page 1 of 1

Some C++ Code

Posted: May 21st, 2004, 2:59 pm
by Smartweb

Code: Select all

void showGraph( void );

double a[10];

int main(int argc, char *argv[])
{
  cout << "SMARTWEB'S NUMBER ADDITION PROGRAM\n\n";
  int sum = 0, count = 0;
  bool done;
  for (int i = 0; i<=9; i++)
  {
    if (!(i == 0))
    {
      if (a[i-1] == 0)
        done = true;
    }
    if (!done)
    {
      cout << "NUMBER: ";
      cin >> a[i];
      count++;
      sum += a[i];
    }
  }
  cout << "\n";
  cout << "NUMBER GRAPH\n";
  showGraph();
  cout << "\n";
  count--;
  cout << "\n";
  cout << "SUM: " << sum;
  cout << "\nCOUNT: " << count << "\n";
  cout << "AVERAGE: " << sum / count << "\n\n";
  return 0;
}

void showGraph( void )
{
  for (int x = -1; x<=9; x++)
  {
    for (int y = 0; y<=10; y++)
    {
      if (x < 0)
        cout << y;
      else
      {
        if (!(a[x] == 0))
        {
	  if(a[x] == y)
            cout << "X";
          else
            cout << " ";
	}
      }
      cout << " ";
    }
    if (!(a[x] == 0) || (x == -1))
      cout << "\n";
  }
  cout << "\n";
}

Posted: May 21st, 2004, 3:09 pm
by Aggressor Prime
Very nice. But would you mind to give an in-depth discusion on what this code does for all of our non C++ programmers out here? I'm guessing it is a calculator program, but you can explain it better.

Posted: May 21st, 2004, 3:16 pm
by Smartweb
For non C++ programmers, what use is looking at this code whatsoever?

Posted: May 21st, 2004, 3:17 pm
by Aggressor Prime
So they can learn. This is a free computer help forum.

Posted: May 21st, 2004, 3:31 pm
by Smartweb
This is a reference for people who know C++, not a tutorial.

Posted: May 21st, 2004, 3:36 pm
by Aggressor Prime
Where is the tutorial on this forum?

Posted: May 21st, 2004, 3:52 pm
by Smartweb
There is none.

Posted: August 19th, 2005, 1:12 am
by lilhawk2892
just tell us wut it does i use c++