Let's start with an easy one. Create an array that stores 4 integers. Ask the user to enter any 4 numbers, one by one. Finally, output those numbers separated by three spaces.
Output:
This program will ask you to enter 4 numbers. It will then confirm your entries.
Enter a number: [user types: 1]
Enter a number: [user types: 2]
Enter a number: [user types: 3]
Enter a number: [user types: 4]
Your numbers: 1 2 3 4
#include<iostream>
using namespace std;
int main()
{
int arr[4];
for (int i = 0; i < 4; i++)
{
cout << "Please, enter a value " << i + 1 << ": ";
cin >> arr[i];
}
for (int i = 0; i < 4; i++)
{
cout << arr[i]<<" ";
}
}
Comments
Leave a comment