Problem with code: Sum of many numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem with code: Sum of many numbers

#include <iostream> using namespace std; void printArray(int arr[], int size) { for(int x=0; x<size; x++) { cout <<arr[x]<< endl; } } int main() { int mainsize; int i; int a; cout<<"Please state the amount of numbers you want to add: "; cin>>mainsize; for(i=0;i>mainsize;i++){ cout<<"Please type the numbers: \n"; cin>>a; int myArr[i]=a; } printArray(myArr, mainsize) ; } }

4th Dec 2017, 5:25 AM
Lead Raven
Lead Raven - avatar
2 Answers
+ 1
in the 2nd for i<mainsize
4th Dec 2017, 6:01 AM
Vinersar Dan
0
also after cin >> mainsize you can declare the array int myArray[mainsize] and delete the int from the 2nd for
4th Dec 2017, 6:04 AM
Vinersar Dan