0

What's error of my code?

#include <iostream> #include<string> using namespace std; int main() { int many; cin>>many; srting chore[many]; for(int i=0;i<many;i++){ cin>>chore[i+1]; } cout<<chore[3]; return 0; }

31st Mar 2021, 6:10 PM
Arash
Arash - avatar
9 Respuestas
+ 1
You are probably trying to access element that does not exist chore[i+1] does not exist for max i value
31st Mar 2021, 6:15 PM
Michal Doruch
+ 1
Indexes start from 0 to many-1 The last element of "chore" has index "many-1" So no, chore[i+1] does not exist for the max i value
31st Mar 2021, 6:40 PM
Michal Doruch
+ 1
Just use [i] instead of [i+1]
31st Mar 2021, 6:42 PM
Michal Doruch
0
Variable chores [i+1] in the For loop It is. At the start of the ring for the value of 0 plus 1 equals 1 so there is
31st Mar 2021, 6:35 PM
Arash
Arash - avatar
0
I don't think there is any data type in cpp called srting
31st Mar 2021, 6:38 PM
Jan
Jan - avatar
31st Mar 2021, 6:41 PM
Arash
Arash - avatar
0
I set the For loop to take all the values of the user if I use' i+1 'instead of' I ' code together
31st Mar 2021, 6:59 PM
Arash
Arash - avatar
0
I made a little test and cin in the for loop doesn't take inputs. It only take inputs in the loop if you remove cin outside the loop.
31st Mar 2021, 7:27 PM
Jan
Jan - avatar
0
i is already incrementing each time the loop runs.. no need to do i+1
2nd Apr 2021, 2:08 PM
Γεωργιος Τανανης
Γεωργιος Τανανης - avatar