I'm new to c++.
I'm trying to build a program that calculate and do operations on some numbers. The problem I'm facing is that I want the use to decide how many numbers he wants the program to compute. So when the program fist starts the use enters a number (lets say 13) then the program should ask the user to enter these numbers separately.
So the problem I'm facing is how would I make the program expect only 13 values and store them to do operations such as adding and averaging on them.
As @keskiverto said you could use the while loop or any other loop,
you just need to compare if the amount of numbers you have stored is equal to the number you gave in the beginning of the program
for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int main()
{
int num=0,i=0;
scanf("%i", &num);
int arr[num];
do
{
scanf("%i", &arr[i]);
i++;
}while(i < num);
for(i=0;i<num;i++)
printf("%i",arr[i]);
return 0;
}
The first loop (do-while) is for storing the int number into the array arr in the position i, it will repeat until i is equal to num-1 because we start storing in arr[0] so if you want to store 10 values they will be stored in the index 0-9
The second loop (for) is just to print the values you just typed in