Yeah, well, programmers stopped using globals to pass parameters and return values decades ago. And for a very good reason you'll find out soon enough if you keep doing it.
Look at what I'm doing in the example and learn how to do it yourself.
(The actual operation is irrelevant. I just put in the for loop to demonstrate array indexing.)
Hang on, could you explain where the linker errors coming from atleast?
Because I understand the idea of indexing, and I know you don't have to return 0 (I just normally do), but above all I am just not seeing where this linker error's coming from, or exactly how to fix it.
Because what's irritating me about it is that I can remove every trace of them from my program yet the error still comes up.
#include <iostream>
#include <math.h>
#include <iomanip>
usingnamespace std;
intconst MAXSTUDENTS = 100;
int getStudentCount();
int noofstu;
int getExamScores();
int ExamScores[];
int num;
int getLabScores();
int LabScores[];
int i;
int calculatePointGrades();
int LSavg[];
int getStudentCount()
{
cout << "Calculating Students Grades" << endl;
cout << "\nHow many students grades would you like to enter today?\n" << endl;
cin >> noofstu;
return 0;
}
int getExamScores()
{
if (noofstu == 0)
{
cout << "You have entered no students, try again" << endl;
}
else
{
for (num=0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Exam Score(s) for student "<< n++ << endl;
cin >> ExamScores[num];
}
int * Examscores = 0;
Examscores = newint;
Examscores = &ExamScores[0];
}
return 0;
}
int getLabScores()
{
for (num =0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Lab Score(s) for student "<< n++ << endl;
cin >> LabScores[num];
}
for (num =0; num < noofstu; num++)
{
LSavg[num] = LabScores[num] * .30;
cout << LSavg[num];
}
return 0;
}
int main ()
{ //Open main
getStudentCount();
getExamScores();
getLabScores();
cin.ignore(2);
return 0;
} // Close main
#include <iostream>
#include <math.h>
#include <iomanip>
usingnamespace std;
intconst MAXSTUDENTS = 100;
int getStudentCount();
int noofstu;
int getExamScores();
int ExamScores[100];
int num;
int getLabScores();
int LabScores[100];
int i;
int calculatePointGrades();
int LSavg[100];
int ESavg[100];
int getStudentCount()
{
cout << "Calculating Students Grades" << endl;
cout << "\nHow many students grades would you like to enter today? (Up to 100)\n" << endl;
cin >> noofstu;
return 0;
}
int getExamScores()
{
for (num=0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Exam Score(s) for student "<< n++ << endl;
cin >> ExamScores[num];
}
for (num =0; num < noofstu; num++)
{
ESavg[num] = (ExamScores[num]* 0.30) ;
cout << "Here's the avg " << setprecision(2) << LSavg[num] << endl;
}
int * Examscores = 0;
Examscores = newint;
Examscores = &ExamScores[0];
return 0;
}
int getLabScores()
{
for (num =0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Lab Score(s) for student "<< n++ << endl;
cin >> LabScores[num];
}
for (num =0; num < noofstu; num++)
{
LSavg[num] = LabScores[num] * 0.30;
cout << "Here's the avg " << setprecision(2)<< LSavg[num] << endl;
}
return LSavg[0];
}
int main ()
{ //Open main
getStudentCount();
if (noofstu == 0)
{
cout << "You have entered no students, try again" << endl;
return 0;
}
elseif (100 < noofstu)
{
cout << "You have exceeded the limit, try again" <<endl;
return 0;
}
else
{
getExamScores();
getLabScores();
}
cin.ignore(2);
return 0;
} // Close main
I'm trying to get the avgs of those two LSavg, ESavg.
I'm getting these warnings:
(51) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(80) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Alright I know why it's happening, i think (decimal being declared double and being forced to convert to int?), but I can't remember how to fix it.
Now the loss of data only occurs for the first avg not the second...I get all the avgs correctly for the second but the first I get 0....
ESavg and ExamScores are arrays of integers. When you multiply an integer by 0.30, the result isn't an integer anymore and the decimal part gets truncated. The loss of data here is the loss of precision, and the compiler is warning that you might not want that.
(I still remember in the old days when I used Turbo C++ version 3.0 or something, the compiler wasn't smart enough to warn you in this situation, and I would get results that didn't make sense.)
This might be an obvious suggestion, but why not use floats or doubles for some of the variables instead?
Got the program built and working.
Compiler's still being wonky but that's another story.
Thank you very much everyone who helped me.
Like I said earlier if it wasn't for the help I'd be rocking back and forth in the fetal position in the corner.