Hello there, I'm practicing structures and accessing data in a structures. I have here a program that gets an input of string and int from a user. I placed it inside a loop where every time the loop refreshes, it changes the information it gets. My problem is, how do i changed the input variable inside a loop?
here is my code, it is unfinished:
#include <iostream>
#include <pthread.h>
#include <string>
#define NUM_OF_STUDENTS 2
#define NUM_OF_INFO 4
using namespace std;
struct Student{
string first_name, last_name, course;
int id_no;
};
void print_student(void* f_name, void* l_name, void* course_, void* id_no_ );
Student student1;
Student student2;
string info[] = {"First Name: ", "Last Name: ", "Course: ", "ID #: "};
int main(){
for(int j = 0; j<NUM_OF_INFO; j++){
cout << info[j];
cin >> student1.first_name;
}
return 0;
}
void print_student(void* f_name, void* l_name, void* course_, void* id_no_ ){
for(int i = 0; i<NUM_OF_STUDENTS; i++){
cout << "STUDENT #" << i+1 << endl;
cout << "First Name: " << *((string*) f_name) << endl;
cout << "Last Name: " << *((string*) l_name) << endl;
cout << "Course: " << *((string*) course_) << endl;
cout << "ID #: " << *((int*) id_no_) << endl;
cout << "\n";
}
}
Notice the for loop inside the main?
string info[] = {"First Name: ", "Last Name: ", "Course: ", "ID #: "};
for(int j = 0; j<NUM_OF_INFO; j++){
cout << info[j];
cin >> student1.first_name;
}
How do I change the input variable every time the loop refreshes? Like when the loop will refresh, the variable student1.first_name will change to student1.last_name coping with the cout << info[j] w/c is, when the loop increments to 1, will write "Last Name: ".
Thank you.