Gaming C++ Epiphany

  • Thread starter Thread starter Sterling
  • Start date Start date
  • Views Views 1,602
  • Replies Replies 6

Sterling

GBAtemp's Silver Hero
Member
Joined
Jan 22, 2009
Messages
4,023
Reaction score
653
Trophies
1
Age
35
Location
Texas
XP
1,130
Country
United States
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;
int * Grades;

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

Grades = new int [n];
cout
 
ThatDudeWithTheFood said:
Good job...?

That was probably the most interesting thing I've read all day.
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.
 
Use functions to clear out main dude
tongue.gif
.
Other than my limited knowledge i'd say it's good.
 
Justin121994 said:
Use functions to clear out main dude
tongue.gif
.
Other than my limited knowledge i'd say it's good.
Believe me when I say that I tried. Still haven't grasped the knowledge of functions very well. :/
 

Site & Scene News

Popular threads in this forum