I'm writing a student management program in C++ for a college project. I have to assign student names by user input, assign 5 different marks that are randomly chosen for each student, then calculate the average of the marks as the first question. And I have to do that using functions only. I can't assign the values inside of main()
.
My code is looking like this so far:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
float random_marks(){
float Q[7];
float j{2};
for(int i{0}; i < 7; i++){
Q[i] = j;
j += 0.5;
}
float x = Q[rand() % 7];
return x;
}
struct student{
string imie;
float oceny[5];
float srednia;
};
student names(student stu[], int N){
float srednia{0};
for(int i =0; i < N; i++){
cout << "Prosze podac imie studenta Nr" << (i + 1) <<endl;
cin >> stu[i].imie;
}
}
student marks(student stu[], int N){
float srednia{0};
for(int i = 0; i < N; i++){
for(int j; j < 5; j++){
float x = losuj_oceny();
stu[i].oceny[j] = x;
}
}
}
int main(){
srand((unsigned) time(0));
int N{0};
cout << "prosze poac liczbe studentow ";
cin >>N;
struct student stu[N];
names(stu, N);
marks(stu, N);
return 0;
}
The functions are not passing the values inside of main()
. I tried to use pointers, but I have an issue using them with a structure.