last day (28 days later) » 

10:45 AM
-3
Q: display number of students in each course

young-I'm trying to create a student data base where by it will display the number of students doing each course. I've created a structure(as a global variable) which will store all student's information from name,surname,age,student ID,course and number of modules.I've used case statements for selecti...

 
Please format your code
 
i have formatted my code @RoQuOTriX,
i have provided the whole program it's not too long @Thomas Sablik
 
@young- a course should be a class, that's why it's extremely complex what you're trying
 
oh. so it's not possible use a structure to display the course.
 
10:45 AM
If this is formatted by any format style it's the worst format style I've ever seen. You can use format.krzaq.cc
 
wouldn't i have to change the whole structure to a class or only change the course to a class.@Moia
well i'm a beginner in programming c++, we are instructed to create a simple program. not too complicated.@ThomasSablik
 
You are using strings and C-style strings. You should avoid C-style strings. Your code is not readable. A formatting makes a code more readable.
 
so which strings are suitable, and what's wrong with C-style strings, i tried the formatting you gave me and it doesn't work. it's my first time hearing of formatting@ThomasSablik
 
Change all char name[80] to string name. There are many disadvantages of C-strings, e.g. the way you would copy them, pass them to a function or return them.
"as a global variable". There aren't any global variables in your code.
 
let me change the char name. i didn't know about C-strings having issues it's truly insightful thanks. so strings are complicated when trying to copy and pass them and return@ThomasSablik
i meant to say function not "Global variable" @ThomasSablik
 
10:45 AM
There are no functions declared in your code. But it would be a great idea to use functions to structure your code.
 
i haven't mastered functions that well, i have a limited time to submit those code as well. i really mix up functions thinking they are structures.
 
Make the code readable and maybe someone will help you. I doubt that someone will read this code.
 
i don't get it. how should i make it readable?
 
@young the function is too long, try to split your code in smaller parts. There are repeating parts, try to remove them in putting them in a seperate function
 
ok i now see what you mean. let me edit the code.@RoQuOTriX
I've just edited the code @RoQuOTriX
 
10:45 AM
Try to create a seperate function for every case in your switch case. e.g. enterRecord, deleteRecord, ... displayRecord and so on...,
 
so when i create those seperate functions I'll be able to access the data in those functions. I'm not too familiar with functions can you help with a snippet of code for either one of them.@RoQuOTriX
 
If your not familiar with functions, you won't success in this task. Dou you know about pass-by-value and pass-by-reference?
 
i have heard of pass-by-value and pass-by-reference, I'm pretty new to programming so i might not know most things
 
Yes we see that you are new to programming, but this are basics of C/C++. Try to learn how to write a function and to use a debugger
 
let me try that@RoQuOTriX
 
 
4 hours later…
2:18 PM
i have already created a separate function, for each case statement @RoQuOTriX
 
 
2 hours later…
4:18 PM
@Moia I've tried to change the course to class but still failed to implement it. wasn't i supposed to change the whole structure to a class. i tried that too but i still can not display all students
 

  last day (28 days later) »