The villiage idiot is back! -Function Help Please???
Hello All!
I am in week three of my C++ class and it still isn't coming easy!
I'm quite sure it never will!! This week I am writing a function to compute grades from numeric to alpha. I am getting an error and I have read everything I can get my hands on and still have no idea. I'm sure just one look from any of you will figure out what I have struggled with for days. (yes days - sick and wrong isn't it!)
Below is the code - function and main .cpp and the header .h files.
Thank you in advance for any assistance you can give me.
mz
This is the main.
Code:
#include <iostream.h>
#include "Calcgrades.h"
void main() //main program
{
float A, B, C, D, F;
char ngrade, lgrade;
float count = 0.0;
A = 0.0;
B = 0.0;
C = 0.0;
D = 0.0;
F = 0.0;
while (count < 10.0); // put at 10 for testing
{
Calcgrades();
}
cout <<"Grades (A, B, C, D, F) : ";
cout <<A<< "," <<B<< "," <<C<< "," <<D<< "," <<F<< endl;
}
Code:
This is the function file:
Code:
char Calcgrades(char lgrade,char ngrade);
{ if (ngrade >= 90)
{ lgrade = A;
}
else if (ngrade >= 80 and < 90)
{ lgrade = B;
}
else if (ngrade >= 70 and < 80)
{ lgrade = C;
}
else if (ngrade >= 60 and < 70)
{ lgrade = D;
}
else if (ngrade < 50)
{ lgrade = F;
}
cout >> "calcgrade lgrade :" >> lgrade >>; endl; //for test
return lgrade;
}
This is the header file.
char Calcgrades();
float count = 0.0;
THANKS!!!!
Re: The villiage idiot is back! -Function Help Please???
Code:
#include <iostream.h>
#include "Calcgrades.h"
void main() //main program
{
float A, B, C, D, F;
char ngrade, lgrade;
float count = 0.0;
A = 0.0;
B = 0.0;
C = 0.0;
D = 0.0;
F = 0.0;
while (count < 10.0); // put at 10 for testing
{
Calcgrades();
}
cout <<"Grades (A, B, C, D, F) : ";
cout <<A<< "," <<B<< "," <<C<< "," <<D<< "," <<F<< endl;
}
function file:
Code:
#include "CalcGrades.h" // Need to include this
char Calcgrades(char lgrade,char ngrade) // get rid of semicolon here
{
if (ngrade >= 90)
{ lgrade = A;
}
else if (ngrade >= 80 and < 90)
{ lgrade = B;
}
else if (ngrade >= 70 and < 80)
{ lgrade = C;
}
else if (ngrade >= 60 and < 70)
{ lgrade = D;
}
else if (ngrade < 50)
{ lgrade = F;
}
cout >> "calcgrade lgrade :" >> lgrade >>; endl; //for test
return lgrade;
}
header file
Code:
char Calcgrades();
extern float count; // make this extern or you will get errors from trying to declare it multiple times
also, this program will go forever calculating grades because count isn't being incremented, you might want to do that somewhere