Values in array aren't printing right

I have a project where i'm supposed to input a list of values in an array and print them. My prints the values but it isn't the values I entered. Instead it prints out some random "20202020202020202" Is there something wrong with my code?

#include <iostream>
#include <string> //any string work include string library
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;
//prototype section
void programInfo();
void inputList(double values[], int MAX_HOURS);
void printList(double values[], int n, int valuesPerLine, int count);
//void sortDescending(double values[], int n);
//double avgList(double values[], int n);
//double stdDev(double values[], int n);
//double medSortList(double values[], int n);
//void printStats(double max, double avg, double std);

int main()
{
const int MAX_VALUES = 20;
double values[20];
int n = 0;
int valuesPerLine = 0;
double max = 0;
double avg = 0;
double med = 0;
double std = 0;
int count = 0;
int values1 = MAX_VALUES;


programInfo();
inputList(values, MAX_VALUES);
printList(values, n, valuesPerLine, count);
// sortDescending(values, n);
// avgList(values, n);
// stdDev(values, n);
// medSortList(values, n);
// printStats(max, avg, std);


cout << "Author: Edwin Trinh\n";

return 0;
}

//definitions section
void programInfo()
{
cout << "Edwin's statistical calculator." << endl;
cout << endl;
cout << "Please follow instruction carefully." << endl;
cout << "Enter a value at a time (at least 3 to up to 20)." << endl;
cout << "You must enter valid data or the program will not work." << endl;
cout << "Enter -1 to signal end of data (-1 or -1.0)." << endl;
cout << endl;
}

void inputList(double values[], int MAX_VALUES)
{
int count = 0;

cout << "Enter a value: " << endl;
cin >> values[count];

while (values[count] != -1)
{
values[count] = MAX_VALUES;
count++;
cout << "Enter a value: " << endl;
cin >> values[count];
}

}

void printList(double values[], int n, int valuesPerLine, int count)
{
for (count = 0; count <= 20; count++)
cout << values[count];
}
Is there something wrong with my code?
If your not getting the results you want, then yes, there is something wrong with your code.

This is why you get nothing but 20's in the beginning.
values [count] = MAX_VALUES;

Your displaying all 20 no matter how many the user enters.
for (count = 0; count <= 20; count++)
Last edited on
Okay thanks! So I got it to output the value in the array except it's only outputting the values in the first spot of the array. How do I assign the variable n so that it becomes the values for however many spots the user enters?

void printList(double values[], int n, int valuesPerLine)
{
int count = n;

for (count= 0; count <= n; count++)
cout << values[n];
}
it's only outputting the values in the first spot of the array.

No idea what this means. Show an example of input and then resulting output. My test yielded exactly how you programmed it.

How do I assign the variable n so that it becomes the values for however many spots the user enters?

Have inputList return count;
Edwin's statistical calculator.

Please follow instruction carefully.
Enter a value at a time (at least 3 to up to 20).
You must enter valid data or the program will not work.
Enter -1 to signal end of data (-1 or -1.0).

Enter a value:
1
Enter a value:
2
Enter a value:
3
Enter a value:
4
Enter a value:
5
Enter a value:
-1
1 Press any key to continue . . .

It only outputs the first value I input into the array, instead of the whole array.

inputList is a module though. I get this error when I try to return count

error C2562: 'inputList': 'void' function returning a value
note: see declaration of 'inputList'
Last edited on
Not sure what to tell you about entries, as when I do it, it populates array accordingly.

change void to in at inputList then you won't get C2562.

int inputList ( double values [], int MAX_VALUES);
You'll have to change the prototype to match.
Last edited on
I'm supposed to use a module for inputList
http://www.cplusplus.com/forum/general/178285/#msg877977


You have duplicate posts going on - THAT IS A TIME WASTER FOR THOSE WHO REPLY

Now we could have 2 or more of us saying the same things in different posts !!

You may think you are going to get more or quicker answers, but all you are doing is creating an annoyance.

Please don't do this :+(
Oops!! Sorry!!! Won't happen again!
Topic archived. No new replies allowed.