Please delete your post. He derives no benefit from you doing it for him. Perhaps you noticed most of us here could easily correct his mistakes, but chose to give guidance instead of doing the work. That's how this board works. So what, he hands in his (your) assignment having learned nothing. How is that helping? Will you be here to do his next assignment too?

ok, first of all... I am learning this on my own... this is not for school... and yes don't give me the answer... but give me what I need to learn... like an example... when you give me the answer I have to go through and learn to see what I did wrong and may assume something that is wrong is right... (if you get what I mean)

To everyone else... I will work on the code again when I get back... and yes I am reading what the compiler is saying, but I just don't know how to fix it... (said isnt it?) well... thats what happens when you are learning...

be back in 5 days... see you all then (wish I had a laptop or netbook)

July 29th, 2010, 01:52 AM

itsmeandnobodyelse

Re: Simple GradeSystem

Quote:

Originally Posted by GCDEF

Please delete your post. He derives no benefit from you doing it for him. Perhaps you noticed most of us here could easily correct his mistakes, but chose to give guidance instead of doing the work. That's how this board works. So what, he hands in his (your) assignment having learned nothing. How is that helping? Will you be here to do his next assignment too?

If you read the post you would see that I explained each single change I had made to the original code. 90% percent of the code I posted was from the OP (that's why there was still some redundant code where I already had posted a different solution). My original purpose was to split the code changes so that little code follows an explanation. Unfortunately that would have required more time than I had yesterday and some of the corrections required changes to different functions. But I will delete the post and do the split today.

Regards, Alex

July 29th, 2010, 06:48 AM

itsmeandnobodyelse

Re: Simple GradeSystem

Quote:

Originally Posted by Zeveso

Ok, I think i got those changes right... but still the program is no where near runable

I hope, you already achieved to solve some of the errors above by applying the advice you got .. but if not I will give you samples of the correct statements to solve each single error:

You currently call the function findLetter with no arguments (you commented the argument list). But your current findLetter has the prototype 'int findLetter(int, char)' and requires 2 arguments. So the following call would compile:

Code:

findLetter(studentAverage, ' ');

You see that I didn't pass the letterGrade which was argument of function writeGrade. That is for two reasons:

(1) the letterGrade in writeGrade is of type int and not of type char
(2) you would pass it as input argument by value to findLetter what makes no sense cause it is a return value of findLetter.

The (1) you can solve easily cause the writeGrade doesn't need an input argument letterGrade as it determines the letter from studentAverage by calling findLetter. Hence, you simply can remove the 'int letterGrade'.

For (2) same applies to the 'char letterGrade' which you don't have to pass to findLetter and remove it from arguments.

I also added gradeFile.close() to the writeGrade. That way the output was flushed to the file and you could look at it while the program is still running. Moreover, some compilers don't like it if a file was opened and opened and never closed ;-)

The error 'gradeSystem.cpp:56: error: expected primary-expression before 'int' ' in saveError was because you have the 'int' in a function call. Argument types generally are wrong syntax when *calling* a function but only when declaring or defining (implementing) it.

So you would need to change

Code:

nowTime(int theTime);

to

Code:

theTime = nowTime();

However, as it seems that you want 'theTime' to be a string expression of the time, the return type should be a char* rather than an int.
Hence, both the 'theTime' variable and the function 'nowTime' should have type char*.

Code:

char * nowTime()
{
...
}

...
// call the function and get char pointer to a local variable
char * theTime = nowTime();

You could get that char* by calling ctime function passing a pointer to the time_t of the current systemtime which you retrieved by a call to time function.

Code:

char * strtime = ctime(&now);

The ctime returns a pointer to a (internal) char array which is null-terminated. After assigninging it to a local char* variable you simply can return it.

In the main function you have a 'while ( canWe = true )' with = instead of == . That way the while loop is endless cause you were assigning 'true' for any cycle.

change the while statement to

Code:

while (canWe == true)
{
...

and you can end the loop by setting canWe to false later.

In the following code you get an iostream error because of 'cin >> canWe;'.

That is cause the istream operator>> doesn't take a right-hand bool variable.

You could solve the issue by using an int variable instead of bool like

Code:

int canWe = 1;
while (canWe)
{
...
cin >> canWe;
}

though the above is very unsafe. If the user enters a non-digit the cin stream would be spoiled and the program hangs. To avoid that, I would recommend using getline for input instead of cin>> . To do so you should add <string> and <sstream> to the includes and use getline wherever you used cin>>.

You see that the getline always returns a string input. That's why in case of 'int studentAverage' or 'bool canWe' we need some kind of conversion. For a simple and error-ignoring way the atoi function is suitable. If you want to go the C++ way you may use a stringstream for convering the input to the studentAverage:

The c_str() returns a const char * from a std::string. Alternatively you could use 'const string &' as argument type of studentName and you can omit the c_str().

Regards, Alex

July 29th, 2010, 07:40 AM

GCDEF

Re: Simple GradeSystem

You're still doing his work for him, and we don't do that here.

August 4th, 2010, 06:28 PM

Zeveso

Re: Simple GradeSystem

Ok, you taught me a couple things for sure. Must say... this was a good learning / wakeup exercise for me. Still not there yet. Working on it, but you did explain many things for me very well.

So I should use char* for all stings instead of char myString[255]?

Also I have not emplimented getline yet because I just want to get the program working first. Then want to do that and clean up the loop some more.

Also, some of those things were so obvious... I can't believe I did not see them. Thanks on those.

If you have time can you explain on how to get the time and use it in a string better? Because I don't get it at all and I feel that is my main problem with my code right now next to not knowing about functions well enough. I am going to read up on both of those after I post this.

If you see anything else, or can think of anything else that can help me let me know.

Thank you very much!!!

PS. Before I tried writing this I did all of the small steps. Like I made a program to write things, and I made one to display the date and time, and I made one that did math... but putting it all together has been a pain.

int main(){
//startup variables that we will use
char studentName[255];
int studentAverage;
int gradeNumber; // amount of student Averages
int totalAmount; //will hold all averages
int submitAmount; //amount submited during for loop session
char letterGrade; // will store the lettergrade before it is written to grades.txt
char * theTime; // will hold the current time
bool canWe; // asks if we can continue

// find out who we will be grading
cout << "Hello user!" << endl;
cout << "This program lets you average the grade of your student and write there grade in a text file." << endl;
cout << "Who will be writting a grade for today?" << endl << "Name: ";
cin >> studentName;
cout << endl << "Ok, we will be grading " << studentName << "today!" << endl;

each char letterGrade is specific to its scope { }. All you did was create temporaries. get rid of the char in front of each letterGrade and add char letterGrade; to the top of the function. this way letterGrade will be local to the function and not to each if statement's scope.

Your comparison test( highlighted in blue ) is brutal and I would not dare to make sense out of it.

Come back with a more compilable program. Please note that if you code does compile, it does not mean it does what you think.

Start with the basics and finish my ConvertScoreToGrade and test it.

August 5th, 2010, 11:14 PM

Zeveso

Re: Simple GradeSystem

@Joeman

You are right... will finish this and check all of it out. I was not trying to build an application to use it, but trying to apply what I thought I had learned. At least this proved one thing, I don't know it yet and need to read more. I have them down 1 by 1, but putting everything together sucks... I am not capable yet.