I'm doing an assignment that involves structs.
You are to make a struct with three variables and declare 3 instances of that struct. The program will then ask for the user to input 9 pieces of information. I don't like having to type cout and cin unnecessarily (9 sequential times?), so I was thinking I could use loops to handle the input, like I've done with arrays earlier. I tried it out, but have been unsuccessful so far. Am I on to something with this?
struct Randomstruct {
int var1, var2, var3;
}
int main() {
Randomstruct struct1, struct2, struct3;
for(int i = 1; i<=3; i++) {
for(int j = 1; j<=3; j++) {
cout << "Enter data for var" << j << " in struct" << struct(i) << ": ";
cin struct(i).var(i);
}
}
}
}
I'm really wondering how I can make the struct(i).var(i) thing work. Is it even possible?