View Full Version : Help with a Programming assignment in C++


AZRoboto
11-03-2008, 11:58 PM
#include <iostream>
using namespace std;

double calcFinalScore(double & t1, double & t2, double & h);
void printFinalScore(double fs);

// *** Add prototypes for readTest1Score, readTest2Score, readHWScore,
double readTest1Score();
double readTest2Score();
double readHWScore();
// *** and readAllScores here.
void readAllScores(double & test1Score, double & test2Score, double & hwScore);

int main()
{
double test1, test2, hw;

readAllScores(test1, test2, hw);

return 0;
}

double calcFinalScore(double & t1, double & t2, double & h)
{
double fs;
fs = 0.4*(t1 + t2) + 0.2*h;
return (fs);
}
void printFinalScore(double fs)
{
cout << "The student's final score is: "<<fs<<endl;
cout << "Their final letter grade is: ";
if(fs >= '90')
cout << "A";
else if(fs >= '80')
cout << "B";
else if(fs >= '70')
cout << "C";
else if(fs >= '60')
cout << "D";
else
cout << "F";
cout << endl;
}

// *** Add implementations of readTest1Score, readTest2Score, readTest3Score,
// *** and readAllScores here.

double readTest1Score()
{
double test1;

cout << "Enter the score for test #1: ";
cin >> test1;

return test1;
}

double readTest2Score()
{
double test2;

cout << "Enter the score for test #2: ";
cin >> test2;

return test2;
}

double readHWScore()
{
double hw;

cout << "Enter the score for the homework: ";
cin >> hw;

return hw;
}

void readAllScores(double & test1Score, double & test2Score, double & hwScore)
{
double finalScore;

readTest1Score();
readTest2Score();
readHWScore();

finalScore = calcFinalScore(test1Score, test2Score, hwScore);
printFinalScore(finalScore);

}

My problem:
I'm trying to have functions that tell the user to enter 3 scores: Test 1, Test 2, and Homework. But in the readTest1Score, readTest2Score, and readHWScore functions, the values stay at zero even after the user inputs a value.

Those three functions take no parameters. When I put in a reference, I get an error. Can anyone help me get this thing working right?

The McMurder
11-04-2008, 12:18 AM
My problem:
I'm trying to have functions that tell the user to enter 3 scores: Test 1, Test 2, and Homework. But in the readTest1Score, readTest2Score, and readHWScore functions, the values stay at zero even after the user inputs a value.

Those three functions take no parameters. When I put in a reference, I get an error. Can anyone help me get this thing working right?

first off your variable names are hard to understand

and i think there is a problem in your final score function

NOTE: i'm still new to c++ but ploogle and silk1000 are both much better than i

EDIT: when i debugged it says that test1 wasn't found... try a different variable

AZRoboto
11-04-2008, 12:30 AM
first off your variable names are hard to understand

and i think there is a problem in your final score function

NOTE: i'm still new to c++ but ploogle and silk91 are both much better than i

yeah, about the variable names, I just followed how the sheet had it. But the calcFinalScore function isn't the problem. It says that each test is worth 40% and the homework is worth 20%.

The problem is that the hw, test1, and test2 variables from their respective functions don't keep their input values. I don't understand what is going wrong, either. I have the return right, I think...

EDIT TO YOUR EDIT: Nah, there's nothing wrong with test1 when I run it.

The McMurder
11-04-2008, 12:35 AM
yeah, about the variable names, I just followed how the sheet had it. But the calcFinalScore function isn't the problem. It says that each test is worth 40% and the homework is worth 20%.

The problem is that the hw, test1, and test2 variables from their respective functions don't keep their input values. I don't understand what is going wrong, either. I have the return right, I think...

EDIT TO YOUR EDIT: Nah, there's nothing wrong with test1 when I run it.

okay i'll keep playing with it... i may change stuff around cause my knowledge is limited

EDIT: WAIT!!!! i feel dumb your variables scope is limited to the function they are called in... so you are trying to do the equations with garbage... (what i'm trying to say is returning your result is right but you need to put it somewhere

double test1;
returns the answer but it's dropped so do it like this then use the new variable as the peramiter instead
double test1Score;
test1Score = double test1;

AZRoboto
11-04-2008, 12:50 AM
Ha, it works!

Now, the only thing is the printFinalScore function. It stays at F

EDIT:

Gots it. Stupid thing I did about that. I added ' ' to the numbers in the if-else statements and we didn't need to do that.

Thanks for the help, man.

The McMurder
11-04-2008, 12:53 AM
Ha, it works!

Now, the only thing is the printFinalScore function. It stays at F

give me your changed code please so i can see it

AZRoboto
11-04-2008, 12:58 AM
give me your changed code please so i can see it

I found out what was wrong (see the edit I made above). Thanks for helping out

The McMurder
11-04-2008, 01:00 AM
I found out what was wrong (see the edit I made above). Thanks for helping out

no problem... sorry it took so long to figure it out

AZRoboto
11-04-2008, 01:04 AM
no problem... sorry it took so long to figure it out

It's all good, man. This means I don't need to go to class tomorrow!

The McMurder
11-04-2008, 01:06 AM
It's all good, man. This means I don't need to go to class tomorrow!

:lol: i'd still recommend going

professors like to cover little things in class only just to catch ya

AZRoboto
11-04-2008, 01:15 AM
:lol: i'd still recommend going

professors like to cover little things in class only just to catch ya

oh nah, tomorrow is Lab day and all we ever do is just what's on the Lab sheets we download from my course's web site.

I know, it sounds easy...it really is, too. Last week we just had to add only 2 functions to a program (which this above is an extension of...printCalcScore and finalCalcScore were the functions we did last week). There's about 30 people in the lab section. Within 25 minutes of class half the people will be finished and gone.

The McMurder
11-04-2008, 01:19 AM
oh nah, tomorrow is Lab day and all we ever do is just what's on the Lab sheets we download from my course's web site.

I know, it sounds easy...it really is, too. Last week we just had to add only 2 functions to a program (which this above is an extension of...printCalcScore and finalCalcScore were the functions we did last week). There's about 30 people in the lab section. Within 25 minutes of class half the people will be finished and gone.

lol i have a lab tomorrow too what level is this 1400?

AZRoboto
11-04-2008, 01:21 AM
lol i have a lab tomorrow too what level is this 1400?

1400?

Nah, this is just CSE 100: Prin of Programming C++. I'm at ASU.

The McMurder
11-04-2008, 01:27 AM
1400?

Nah, this is just CSE 100: Prin of Programming C++. I'm at ASU.

hmmm... well my class is CS1400 and my lab is 1405 i guess leveling systems are different in various areas... learn something new everyday

AZRoboto
11-04-2008, 01:31 AM
hmmm... well my class is CS1400 and my lab is 1405 i guess leveling systems are different in various areas... learn something new everyday

Yeah. Different accreditation, I guess. the next level is 205 for me. I don't know the exact name, though.

Ploogle
11-04-2008, 12:15 PM
I know the problem has been solved, but I just had a question:

Why did you choose to make "ReadAllTestScores" (Or whatever it was called) void? Why not make it return a double? It's a good idea in general to not use pointers unless there's a logical reason to do so, or you could be looking at a nightmare to debug. Was that part of the assignment?

slik1000
11-04-2008, 01:37 PM
some of your function names were fine so far as I can see, but never ever use anything like "fs" as "finalScore" if you did that at a professional level you would be hauled into the office and beaten. There's a standard way of naming them. a non caps letter followed by caps for every new word likeThisAndThisAndThis. You did it on a couple, but it seemed to slip later in the code.

Why didn't you comment your code? it makes debugging much easier, a simple "Declared Variable, and initialised at 12" is all it needs to be at the end of important lines. It taks longer to write out, but when you make a mistake (and we all make mistakes, every10 mins) it's much easier to figure out, or get other people to find out if it's been commented. Even if it's not part of your course content, you should still be commenting! It's better to get into the practice now.

As for Ploogles question, I'm guessing they haven't gone through all the basic syntax, and the advantages to each one. It was probably explained in one of those labs that he missed. GO TO YOUR LAB SESSIONS!

While we're all here, does anyone know how to make the motherboard beep?

The McMurder
11-04-2008, 03:56 PM
some of your function names were fine so far as I can see, but never ever use anything like "fs" as "finalScore" if you did that at a professional level you would be hauled into the office and beaten. There's a standard way of naming them. a non caps letter followed by caps for every new word likeThisAndThisAndThis. You did it on a couple, but it seemed to slip later in the code.

Why didn't you comment your code? it makes debugging much easier, a simple "Declared Variable, and initialised at 12" is all it needs to be at the end of important lines. It taks longer to write out, but when you make a mistake (and we all make mistakes, every10 mins) it's much easier to figure out, or get other people to find out if it's been commented. Even if it's not part of your course content, you should still be commenting! It's better to get into the practice now.

As for Ploogles question, I'm guessing they haven't gone through all the basic syntax, and the advantages to each one. It was probably explained in one of those labs that he missed. GO TO YOUR LAB SESSIONS!

While we're all here, does anyone know how to make the motherboard beep?

isn't it just \a

slik1000
11-04-2008, 04:11 PM
that's what I had, but I'm getting illegal escape sequences. is it in <iostream>? or a different library?

The McMurder
11-04-2008, 04:43 PM
that's what I had, but I'm getting illegal escape sequences. is it in <iostream>? or a different library?

\a is in the standard library i believe... i just tried it in visual studios and it works just fine

slik1000
11-04-2008, 05:57 PM
nope, it's not working. I'm still getting the errors :(

The McMurder
11-04-2008, 06:29 PM
nope, it's not working. I'm still getting the errors :(

try #include <iomanip>;

other than that i'm not sure

EDIT: a quick google search showed this (http://apps.carleton.edu/curricular/cs/resources/source/beep_prog/)

slik1000
11-04-2008, 06:32 PM
Nope, no luck. I'm on a different compiler though. I'll try it on the windows (urgh) compiler at uni in the morning.

The McMurder
11-04-2008, 06:34 PM
Nope, no luck. I'm on a different compiler though. I'll try it on the windows (urgh) compiler at uni in the morning.

what's so bad about it? seems fine to me but i guess it's the only one that i've used

slik1000
11-04-2008, 06:36 PM
GCC is much better. I don't really like IDE's. The only thing that I actually like about VS is that the compiler warnings are readable.

The McMurder
11-04-2008, 06:37 PM
gcc is much better. I don't really like ide's. The only thing that i actually like about vs is that the compiler warnings are readable.

gcc? Ide?

AZRoboto
11-04-2008, 06:37 PM
I know the problem has been solved, but I just had a question:

Why did you choose to make "ReadAllTestScores" (Or whatever it was called) void? Why not make it return a double? It's a good idea in general to not use pointers unless there's a logical reason to do so, or you could be looking at a nightmare to debug. Was that part of the assignment?

That was part of the assignment. The readTest1(2)(hw)Scores functions had to be double, and that one ^^^^ had to be void.

The McMurder
11-04-2008, 06:38 PM
That was part of the assignment. The readTest1(2)(hw)Scores functions had to be double, and that one ^^^^ had to be void.

i hate the stupid rules like that!

AZRoboto
11-04-2008, 06:45 PM
some of your function names were fine so far as I can see, but never ever use anything like "fs" as "finalScore" if you did that at a professional level you would be hauled into the office and beaten. There's a standard way of naming them. a non caps letter followed by caps for every new word likeThisAndThisAndThis. You did it on a couple, but it seemed to slip later in the code.

Why didn't you comment your code? it makes debugging much easier, a simple "Declared Variable, and initialised at 12" is all it needs to be at the end of important lines. It taks longer to write out, but when you make a mistake (and we all make mistakes, every10 mins) it's much easier to figure out, or get other people to find out if it's been commented. Even if it's not part of your course content, you should still be commenting! It's better to get into the practice now.

As for Ploogles question, I'm guessing they haven't gone through all the basic syntax, and the advantages to each one. It was probably explained in one of those labs that he missed. GO TO YOUR LAB SESSIONS!

While we're all here, does anyone know how to make the motherboard beep?

Most of the program was copied/pasted from what we did last week in lab, except for the four read functions. I didn't feel like going into the program I created then with the logically-named variables, so I copied/pasted the one from the lab sheet (which was the same except for the naming).

In the homework I comment whenever I can, though.

And the only lab I ever missed was this one!! We get the entire assignment beforehand, so I know I didn't miss anything.

The McMurder
11-04-2008, 06:46 PM
so I know I didn't miss anything.

uh... huh... yet!

slik1000
11-04-2008, 06:49 PM
gcc? Ide?

GCC means something like Gnu C Compiler, it's just a little more basic than VS, there is no point in having all the project crap unless you are actually working on a project.

IDE means "intigrated Development Enviroment, basically the thing that turns all the words like bool and void blue and comments green. I don't like it, because now and then it's wrong and it tries to second guess me (like if you have a variable that contains a key word, it will sometimes colour it blue. Really gets on my last nerve when I'm trying to program.

i hate the stupid rules like that!

me too, they really go against the whole point of learning a programming language.

The McMurder
11-04-2008, 06:52 PM
GCC means something like Gnu C Compiler, it's just a little more basic than VS, there is no point in having all the project crap unless you are actually working on a project.

IDE means "intigrated Development Enviroment, basically the thing that turns all the words like bool and void blue and comments green. I don't like it, because now and then it's wrong and it tries to second guess me (like if you have a variable that contains a key word, it will sometimes colour it blue. Really gets on my last nerve when I'm trying to program.
really that's it? i like how the environment is helpful... 90% of the time


me too, they really go against the whole point of learning a programming language.

yeah it disgusts me

AZRoboto
11-04-2008, 06:53 PM
uh... huh... yet!

This is the 10th lab, man. One week, all we did was make a do-while statement. Only problem with that was...

...EVERYTHING in the do while statement was already written! We just needed to put:

do
{
[all this junk was already written]
}
while([whatever this was])

Seriously!

The McMurder
11-04-2008, 06:53 PM
This is the 10th lab, man. One week, all we did was make a do-while statement. Only problem with that was...

...EVERYTHING in the do while statement was already written! We just needed to put:

do
{
[all this junk was already written]
}
while([whatever this was])

Seriously!

:lol::lol::lol: i was just messing with you man

slik1000
11-04-2008, 06:54 PM
how much are you paying for this course? I think you should talk to your module/course leaders about that.

AZRoboto
11-04-2008, 07:00 PM
:lol::lol::lol: i was just messing with you man

Ya, I know

how much are you paying for this course? I think you should talk to your module/course leaders about that.

I don't know, I'm on a scholarship, so I didn't pay attention to the fees per class.

I did tell him how easy it was, though, especially with that waste-of-time do-while lab four weeks ago where we added only two godjfkamnmothergkfjldiofj lines! He said he'd make it a bit harder, which he has done since then.

He also said that he's making it easy to follow because it's "like a whole new language you have to learn." Which I guess is fair, because there's a large division in my class between who gets it and who doesn't.

The McMurder
11-04-2008, 07:02 PM
Ya, I know



I don't know, I'm on a scholarship, so I didn't pay attention to the fees per class.

I did tell him how easy it was, though, especially with that waste-of-time do-while lab four weeks ago where we added only two godjfkamnmothergkfjldiofj lines! He said he'd make it a bit harder, which he has done since then.

He also said that he's making it easy to follow because it's "like a whole new language you have to learn." Which I guess is fair, because there's a large division in my class between who gets it and who doesn't.

same in mine... i get pretty much everything with no problems but some people just struggle and struggle

The McMurder
11-05-2008, 02:25 PM
i created a social group for programmers... and ones in training where this discussion can continue

cause we're WAYYY off topic

so... i can't seem to remember how to loop til the end of a file

nevermind got it