# C++ Epiphany

Discussion in 'Computer Games and General Discussion' started by Sterling, Sep 26, 2010.

# C++ Epiphany

1,010 Views
1. ### SterlingGBAtemp's Silver Hero

Member
6
Jan 22, 2009
Texas
So, I have taken a class on C++ and for my second assignment I an required to ask for user input and based upon said input, I calculate the average and output it to the console. I did a simple main() iteration, and I wasn't satisfied. So I decided to take a concept of an undefined sized array which stores an [in]finite amount of entries, and when prompted takes the entries and calculates the average. A concept that was fairly easily implemented on JAVA.

Flow Chart:

1) Variable initialization

2) Ask user for input to be stored in an array whose size is defined by a conditional infinite break loop (It's a for loop, but I think it could be done with a Do while loop).

3) When loop is broken, recall entries and add them together for the sum.

4) Calculate the average based on the loop variable.

5) Output

The first thing I learned is the fact that this isn't as easy as it was in Java. I had to first figure out how to bypass the fact that array initialization cannot be innately undefined. I had to create a pointer value and get familiar with the concept of dynamic memory. After I figured that out it was just a matter of time.

Code:
CODE/*
*Sterling Schneider
*Culbertson
*Lab 2: Challenge
*Using arrays and loops and functions
*/

#include
#include

using namespace std;

int Exit = 0;

int main()
{

int Sum = 0;
int Ave = 0;
int e = 0;
int n = 1;

//*********//

cout

2. ### ThatDudeWithTheFoodTRIANGLEZ

Member
4
Mar 9, 2009
Illuminati
Good job...?

That was probably the most interesting thing I've read all day.

3. ### SterlingGBAtemp's Silver Hero

Member
6
Jan 22, 2009
Texas
Thanks. I'll accept that if it isn't sarcasm. ^.^

Took maybe an hour to sort through several google searches and tutorial sites. It could be better, but I have a feeling that my teacher may pat me on the back in it's current condition.

4. ### Joe88[λ]

Moderator
14
Jan 6, 2008
why is exit a global variable
you never leave main

5. ### Justin121994Bitcoin. coinbase.com/andrew

Member
2
Jan 12, 2009
Ontario, CA
Use functions to clear out main dude .
Other than my limited knowledge i'd say it's good.

6. ### SterlingGBAtemp's Silver Hero

Member
6
Jan 22, 2009
Texas
Believe me when I say that I tried. Still haven't grasped the knowledge of functions very well. :/

7. ### Justin121994Bitcoin. coinbase.com/andrew

Member
2
Jan 12, 2009
Ontario, CA
Oh then thats good.
I'm a lil farther.
I'm just stuck with school work.. Stupid ap classes, that I have no time for it.
Well good luck.
http://www.learncpp.com/
Heres a site I've been using for c++ it's really good.