0
Anyone knows how to solve this
#include <iostream> #include<string> using namespace std; struct student { string name; int id; }; const int ENTRIES = 3; int main () { student alpha[ENTRIES] ; for(int i =0; i<ENTRIES; i++) { cout <<"Enter name and id\n"; cin >>alpha->name; cin>>alpha->id; } return 0; } My for loop isn't working because of the last statement
3 Respostas
+ 7
Decoder 👩💻 You need to provide details on what you expect to happen with your code. We have no idea what the mistake could be when there is not any compile error.
But...
Part of your problem likely has to do with the fact that you are declaring an array but you are not assigning the values in your for loop to a unique index of that array. Therefore each value gets assigned to index 0 and overwrites all previous values.
student alpha[ENTRIES] ;
Assignment in for loop should be cin >> alpha[i].name;
+ 4
Your loop is running 3 times only (for "i" = 0 ,1 and 2)
What is the problem you are facing here ?
0
Btw, if i may ask do u know how to stop a file from over writing?