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
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






