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; }
9 Respuestas
+ 1
You are probably trying to access element that does not exist
chore[i+1] does not exist for max i value
+ 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
+ 1
Just use [i] instead of [i+1]
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
0
I don't think there is any data type in cpp called srting
0
https://code.sololearn.com/cao0k6bxZcr4/?ref=app
I used string in this code
0
I set the For loop to take all the values of the user if I use' i+1 'instead of' I ' code together
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.
0
i is already incrementing each time the loop runs.. no need to do i+1