Question

# In C plus plus Objective: Create an array of numbers based upon user input. Program logic:...

In C plus plus

Objective: Create an array of numbers based upon user input.

Program logic:

Ask the user for how big to size the array.

Create an array based upon that size.

Repeat adding to the end until all numbers have been entered or until they enter -1 for the number.

Print the list.

Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<iostream>
using namespace std;
int main(){

int n;
cout<<"How big to size the array?: ";
cin>>n;
int a[n],counts=0;
for(int i=0;i<n;i++)
{
cout<<"Enter a number or press -1 to stop: ";
int p;
cin>>p;
if(p==-1)
break;
a[i]=p;
counts++;
}
cout<<"The list is: ";
for(int i=0;i<counts;i++)
{
cout<<a[i]<<" ";
}
return 0;

}

Kindly revert for any queries

Thanks.

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
• ### Create a program that takes in user input and stores the input into an array. Also...

Create a program that takes in user input and stores the input into an array. Also within the program show how you can: show the elements in the array, remove an element from the array, add an element to the array. Do NOT ask the user how many elements they want to add, instead once they are done adding, they should hit ‘q’ and it should break out of the input. This is a c++ program. The input type shall...

• ### Write a program which will take a list of integer number from the user as input...

Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...

• ### // 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...

• ### C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating...

C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating it's values. Then, we'll use the values in the array to calculate the average. Since it's common for an average to result in numbers with decimal points, the array you create should be of type double[]. This program will need to use dynamic input from the user so perform the following steps: Ask the user how many numbers need to be added. Use this...

• ### (C programing, Not C++) Write a program in C that asks the user to input 10...

(C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

• ### Please complete this code for java Lab Write a program as follows: Create an array with...

Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

• ### 1. Write a program to add positive numbers. Ask the user to enter numbers greater than...

1. Write a program to add positive numbers. Ask the user to enter numbers greater than zero. If a 0, is entered stop requesting numbers and display the total. If a number is entered that is less than 0, display the message ‘Number must be greater than 0’, then ask for another number to be entered. Repeat until a number greater than 0 or 0 is entered. use math lab so I can copy the answers

• ### You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an...

You are to write a program (BookExceptionsDemo.java) that will create and, using user input, populate an array of instances of the class Book. The class Book is loaded in our Canvas files: Book.java The user will enter a number n (n must be > 0, trap the user until they input a valid value for n), Your program will declare and create an array of size n of instances of the class Book. The user will be asked to enter...

• ### Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

• ### write in python Create a program that will ask the user for a list of integers,...

write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...