lundi 31 janvier 2022

How to store each user input into array?

I used a do while loop to ask user to enter integer as long as its not 0 or it will exit the program. I'm stuck on how to store every user input into the dynamically allocated array.

#include <iostream>
using namespace std;


int main() {
  int *A;
  A= new int();
  int n;
  do{
    cout<<"Enter integer: "<<endl;
    cin>>n;
    cout<< *A + n << endl;

    
  }while(n!=0);

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire