Question

// Program takes 5 numbers from a user (from console), stores them into an // array,...

// Program takes 5 numbers from a user (from console), stores them into an
// array, and then prints them to the screen (on the same line).

// Add code to complete this program. You only need to add code where indicated
// by "ADD HERE".

#include <iostream>
using namespace std;

int main()
{
        const int SIZE = 5;  // size of array

        // ADD HERE - create an array of integers that will hold 5 integers.


        cout << "please enter 5 integers : " << endl;

        // For loop takes 5 integers from user and stores them in the array
        for (int i = 0 ; i < SIZE ; i++)
        {
                // ADD HERE - take user's input and store it in the array you created
        
        
        }

        // ADD HERE - Write a for loop to print the array to the screen


        return 0;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main()

{

        const int SIZE = 5; // size of array

      int a[size];

        cout << "please enter 5 integers : " << endl;

        // For loop takes 5 integers from user and stores them in the array

        for (int i = 0 ; i < SIZE ; i++)

        {

          cin>> a[i];

       

       

        }

for (int i = 0 ; i < SIZE ; i++)

        {

          cout >> a[i];

       

       

        }

        return 0;

}

Add a comment
Know the answer?
Add Answer to:
// Program takes 5 numbers from a user (from console), stores them into an // array,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that simulates a lottery. The user will select 5 numbers 0 through...

    Write a C++ program that simulates a lottery. The user will select 5 numbers 0 through 9 and put this in an array. Then these user numbers are compared to the random numbers the computer generated. The program will display both the computer random number and below the user selected numbers. The program will tell the user how many matches are made. If the user guesses all five you let them know they are the grand winner. Here is the...

  • Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array...

    Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array and // its size and returns the index of the first occurrence of the largest element II in the array. Also, write a function to display the array #include ·peh.h" #include <iostream> using namespace std const int ARRAY_SIZE = 15; int main int list[ARRAY SIZE56, 34, 67, 54, 23, 87, 66, 92. 15, 32, 5, 54, 88, 92, 30 cout < List elements: "...

  • /* Array expander: Write a function that accepts an int array as argument. The function should...

    /* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array */ #include <iostream> using namespace std; const int NUM_ELEM...

  • Am I using the right cin statement to take in values for my array? If I...

    Am I using the right cin statement to take in values for my array? If I print them out it prints "0x61fea0" with the input 1 2 3 4 5 ///////////////////////////////// #include <iostream> using namespace std; const int ARRAY_LENGTH = 5; int main(){ int numbers[ARRAY_LENGTH]; int threshold; //@todo prompt user to enter array values cout << "Please input 5 numbers: " << endl; for(int i = 0; i < ARRAY_LENGTH; i++){ //@todo add cin statement to read in values for...

  • Finish the following program which adds up all integers from 0 to the user's given number inclusively using a While Loop

    // Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...

  • C++ ProgrammingWrite a function that takes an integer array, the array size and a number....

    C++ ProgrammingWrite a function that takes an integer array, the array size and a number. And it determines how many times that number appears in the array. Just copy the following code and paste it to your answer. And fill the corresponding part. #include < iostream >using namespace atd; int howmany (int array lint , int number){ //Your code comes here} int main() {const int N =10; int array[N] = [11,3,2,1,3,4,6,9,1.3); int count = howlany(array,N,3);cout << 3 < "appesa" << cout << "times!"; return 0;

  • // This program will read in a group of test scores (positive integers from 1 to...

    // This program will read in a group of test scores (positive integers from 1 to 100) // from the keyboard and then calculate and output the average score // as well as the highest and lowest score. There will be a maximum of 100 scores. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...

  • This program has an array of floating point numbers as a private data member of a...

    This program has an array of floating point numbers as a private data member of a class. The data file contains floating point temperatures which are read by a member function of the class and stored in the array. Exercise 1: Why does the member function printList have a const after its name but getList does not? Exercise 2: Fill in the code so that the program reads in the data values from the temperature file and prints them to...

  • Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp...

    Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp Is posted here: // This program reads data from a file into an array. Then, it // asks the user for a number. It then compares the user number to // each element in the array, displays the array element if it is larger. // After looking at entire array, it displays the number of elements in the array larger // than the user...

  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT