That doesn't sound very clear, perhaps you might explain what problem you are trying to solve. Or show the code you have so far and where you are getting stuck.
let's say i have a for loop: for(int i=1;i<=5;i++). and i want to add 1,2,3,4,5 to an array, let's say int Arr[4]. how do i go about doing that? i have some failed attempts, most of the time i get a random number when i print the array
#include <iostream>
//Function Prototypes.
void InputIntoArray(int[], int);
void OutputFromArray(int[], int);
int main()
{
constint SIZE{ 5 }; //Declare and define the size of the array.
int ArrNum[SIZE]{0}; //Declare and define the values into the array, which is zero.
InputIntoArray(ArrNum, SIZE); //Call the first function to ask the user to input the integers.
OutputFromArray(ArrNum, SIZE); //Call the first function to ask the user to output the integers.
return 0;
}
//This function runs a for loop in accordance
//with the size of the array (variable :sz)
//to obtain the input from the user.
void InputIntoArray(int arrayNumber[], int sz)
{
std::cout << "Input an integer number " << sz << " times.\n";
for (int count = 0; count < sz; count++)
{
std::cout << "Number " << count + 1 << ": ";
std::cin >> arrayNumber[count];
}
}
//This function runs a for loop in accordance
//with the size of the array (variable :sz)
//to obtain the output from the user.
void OutputFromArray(int arrayNumber[], int sz)
{
std::cout << "Outputting the numbers you inputted...\n";
for (int count = 0; count < sz; count++)
{
std::cout << "Number " << count + 1 << ": ";
std::cout << arrayNumber[count];
std::cout << std::endl;
}
}