mardi 25 janvier 2022

Is there a way to use input variable as size of an array in C++? [duplicate]

I want the user to decide the array length by using cin. I have tried changing the scope but as expected it doesn't work. I would be grateful if you suggest me some changes in the code or the approach. Thank you.

#include <iostream>
using namespace std;

//declaring functions
void choose();
void add();
void average();
void product();
//declaring global variables
int choice;
double price[size], sum, avg, pro;

int main(){
    cout<<"Enter the number of items: ";
    cin>>size;
    choose();
    return 0;
}
.
.
.

Aucun commentaire:

Enregistrer un commentaire