I'm having trouble creating a program that returns the user's integers. It returns the first integer and then gives me values for the rest of integers. It should print something like this:
Enter number of integers: 5
Enter integers: -3 -4 6 7 23
You entered: -3 -4 6 7 23
This is my code so far:
#include <iostream>
using namespace std;
int main(){
int *dynArray; // pointer to the dynamically allocated array
int size; // array size
cout << "Enter number of integers: ";
cin >> size;
dynArray = new int [size];
cout << "Enter integers: ";
//for(int i = 0; i < size; i++)
cin >> *dynArray;
I commented out the first for loop because after I entered the integers, the program ended. Having that for loop commented out allowed it to print my third line with at least one integer
Hmm.... that's really weird. When I enter that same exact code into Microsoft Visual Studio, it tells me there are build errors and won't even let me run the program
---------------------------
Microsoft Visual C++ 2010 Express
---------------------------
Unable to start program 'C:\Users\Owner\Documents\Visual Studio 2010\Projects\Practice_pg150\Debug\Practice_pg150.exe'.
The system cannot find the file specified.
---------------------------
OK
---------------------------
I created a new project and pasted the code in so now it is allowing me to run it! The only problem I'm having now is....after I enter integers, my program just exits and does not print back the numbers I entered
That's just how your IDE acts. There should be an option of Run Without Debugging that will keep the window open for you. Alternatively, you can run it from a command line. I recommend learning how to do this at some point.