Hy guys. I am new here and I need your help.Long story short I want to improve my efficiency at work and for that I want to write a small program in C++ , because I learned C++ long time ago in high school..
What do I need from the program :
1.I need to enter several variables from the keyboard , for example today will arrive 4 transports , next week 7 transports and for every transport I need to enter to cost individual . I thought to use array and here is my following try:
1 2 3 4 5 6 7 8 9 10 11
int n; // n will be the number of transports that will change every time
int i;
cin>>n;
double receptii[n];
for(i=0;i<n;i++)
{
cin>>receptii[i];
}
return 0;
}
2.Of course the transports will suffer some operations (*-+/) and I need them to take individual , sum them and cout<< them .
I hope that express myself correctly.
Thank you in advance.
int n;
int i;
cin>>n;
double receptii[n]; // a big nono
This is forbidden/illegal in c++. Arrays has to be constant at compile time. I would suggest you use an std::vector, but if you insist on using an array, you'd have to dynamically allocate memory.
1 2 3 4
int n;
int i;
cin>>n;
double* receptii = newdouble[n];