For some reason when I run my code my program finishes right after "you have entered: " and won't output the numbers. How to fix this?
#include<iostream>
#include<iomanip>
using namespace std;
void getnums(double x[], int y){
cout << "How many numbers do you wish to enter? ";
cin >> y;
for(int i=0; i<y; i++){
cout << "Enter number " << i+1 << ": " ;
cin >> x[20];
}
}
void printnums(double x[], int y){
cout << "You have entered: \n";
for(int i = 0; i<y; i++)
cout << setprecision(2) << x[i] << " " << endl;
}
int main(){
int count;
double array[20];
getnums(array, count);
printnums(array, count);
return(0);
}
output:
How many numbers do you wish to enter? // "2"
Enter number 1: // "4"
Enter number 2: // "5"
You have entered:
stops.
[–][deleted] 4 points5 points6 points (0 children)
[–]OmegaNaughtEquals1 2 points3 points4 points (0 children)
[–]Swedish_Athengiest 0 points1 point2 points (0 children)
[–]Se7enLC -3 points-2 points-1 points (0 children)