Beginning Tutorials

This is a discussion on Beginning Tutorials within the C++ Programming forums, part of the General Programming Boards category; My first post.
I am trying to learn C++ and have been reading the tutorials (learn something! Presidential order…seams reasonable). ...

Beginning Tutorials

My first post.

I am trying to learn C++ and have been reading the tutorials (learn something! Presidential order…seams reasonable). Books are on the way. Anyway, as an exercise, I’ve taken some of the tools presented here and put them into one thing.

Ok, it kinna sorta does what I expected. BUT! I expected it would quite automatically if case 4 were in play. It doesn’t. It just continues to loop. Same with default. Any hint about what I’m missing? I’ve tried sooooo many things, too many to list here.

Thanks,Sug

Last edited by Salem; 12-28-2011 at 07:46 AM.
Reason: removed most of the formatting disaster

case 4:
cout<<"Thank you for playing!\n";
break; // I think you know what "break" is supposed to do.
a=0; // so perhaps this is in the wrong place? ;)

I expected it would quite automatically if case 4 were in play. It doesn’t. It just continues to loop.

Well, here's the loop condition:

Code:

for (;a=1;)

When I started programming seriously I had to write a giant:==
at the top of my keyboard because I made this mistake so often and couldn't see it. That's the equality compare operator. "=" is the assignment operator.

Keep in mind that even if you correct that, you still have the problem I first mentioned.

Your indentation is horrible. This is a high priority item to fix.
Also, these
float mult ( int x, int y );
make no sense. They are function declarations, but you have no such functions in your code.
Even if you were to define a function, you can't define them within another function (they must be outside other functions), plus, you never really call them. So review functions.

Hey! Fixed it! Although it was not something that ever had to be fixed really. I’m not getting paid or graded for this. Nevertheless it is very cool to see it do what I expect it to do. While I am happy about that I realize there is a looooooong way to go. Sure it does what I expect but I do not know why and until I do know why I don’t know jack.
MK27 you were spot on. I did 2 things.

Code:

int main(){a=1;for (;a==1;)

And

Code:

case 4:a=0;cout<<"Thank you for playing!\n";break;

Elysia, I looked up the indent thing. I’ll work on it.
There is one thing though…If float mult ( int x, int y ); makes no sense then why does it work? If I write int mult (intx, inty); and the compile and try to multiply say 3.14159 times 5.5 the result is a computerized hissy fit. But float mult (intx, inty); yields an acceptable result. Therefor it makes some sense, maybe not all the sense available but some portion of sense. That said I will keep all that everyone has put forth here in mind as I push on.

There is one thing though…If [/SIZE][/FONT][COLOR=black][FONT=Verdana]float mult ( int x, int y ); makes no sense then why does it work? If I write int mult (intx, inty); and the compile and try to multiply say 3.14159 times 5.5 the result is a computerized hissy fit. But float mult (intx, inty); yields an acceptable result. Therefor it makes some sense, maybe not all the sense available but some portion of sense. That said I will keep all that everyone has put forth here in mind as I push on.

Ah, post hoc, ergo propter hoc.

The statement
float mult ( int x, int y );
is a function declaration, also known as a function prototype. There is no restriction in the placement of such statements. You can in fact declare functions anywhere, but you shouldn't want to do it exactly like that. Be organized; declare functions in one place at the top of a file. There usually aren't any problems as far as compiling is concerned until you actually call the function. There has to be a definition, somewhere, that explains what mult does.

Like that. Since you didn't actually call mult there was no obvious problem.

To additionally clarify things, I will say that you opted to compute the results inline like this.

Code:

cout<<"The product of your two numbers is "<< x * y <<"\n";

So that protected you from problems.

Basically, my advice is if you want to write functions, please also try to use them. The compiler is very good at tweaking you about errors with functions and their calls. Also please don't focus on making your posts look fancy anymore.