hacking contest

hacking exploits security forum
hacking
compliance articles
upgrade backup exec
information security consultant

Full Version: Whoever Knows C++
RealityFusion
Just wondering if anyone here could come up with a nice exercise for a beginner C++ learner? Or if you know any good url that give some.
[orion]FTF
I have a few e-books about c++ i can mail you, if thats any good...?
RealityFusion
Sure anything will help. As of right now I am testing my skills in writting functions. The program I have going is quite interesting and challenging for me. I am trying to calulate the age difference between 2 people, then the part I just started to add, is to calculate how old someone will be when the other person is a certain age. It's going pretty good right now no problems so far.

You can send me the e-books but I am not to sure if you can access my e-mail. If you can go ahead, but if you can't would it be safe for me to put it up on this forum?

Thanx
RealityFusion
Well I think I just ran into my first problem. I am going to research it first before I go about asking for a solution. But I guess I could ask the question indirectly.

I am not sure about the procedures for posting code on this forum so if I do it wrong please correct me.

+++++++++++++++++++

# include <iostream.h>

int Diff(int a, int cool.gif
{

cout << "In Diff(), received " << a << " and " << b << ".\n";
return (a-cool.gif;

}

int GetAge(int a,int y)
{

cout << "In GetAge() , received " << y << " also received " << a << ".\n";
return (y-a);
}

int main()
{
cout <<"I'm in main.\n";
int a, b, c, x, y, z, f;
cout <<"This function will hopefully calculate the age difference between\n";
cout <<"me and my nephew.\n";
cout <<"Enter your age.\n";
cin >>a;
cout <<"Enter your newphews age.\n";
cin >>b;
cout <<" \nCalling Difference()\n";
c=Diff(a,cool.gif;
cout <<"Back in main.\n";
cout << "c was set to " << c << ".\n";


cout <<"Now lets try something a little more complex ok?\n";
cout <<"This time we will calculate how old your nephew will be when you are a certain age.\n";
cout <<"How old do you want to be?\n";
cin >>y;
z=GetAge(a,y);
cout <<"The age difference between your actual age and the age you want to be is " <<x << ".\n";
cin >>f;

return 0;
}

+++++++++++++

My problem is that when I am calling the function GetAge() to return the value I get one screwed up number. I am thinking that I am going to have to use a getline. Not sure on how that works yet but that is what I am about to check. Wish me luck. O yes, and one more thing. I have been trying to look for an answer to this question for days and have not been able to find it. When I compile a program and it has no input statments the screen just pops up and goes away so fast, for example, in the "hello world" tut it goes so fast that I don't even get a chace to see it. I took a class for this in High School and I remeber that after every program it said to hit any key to contiune then it would go away. I don't remeber what it was that did that. I will keep looking though.
linuxwolf
Try that again, this time disable emoticons smile.gif
[orion]FTF
[QUOTE]When I compile a program and it has no input statments the screen just pops up and goes away so fast, for example, in the "hello world" tut it goes so fast that I don't even get a chace to see it. I took a class for this in High School and I remeber that after every program it said to hit any key to contiune then it would go away[/QUOTE]

You could make an "Exit(Y/N):"... the easiest way is to include 'stdlib.h' then type in this line at the end of program: [CODE]system("pause")[/CODE] - this will use the windows command 'PAUSE' to make the "Press any key to continue..."-function...
else you could make something like

[CODE]
char exit;
cout << "Exit(Y/N): " ;
cin >> exit;[/CODE]

if you want to be able to run the program again, by pressing 'N', just make an 'IF setence'... don't have time to type anymore at the moment... but i guess you can figure the IF setence out on your own, right? ;-)
RealityFusion
Well I did that program the way I should have done it all along and figured out the problem by myself. It's always the little things that trip me up. rolleyes.gif
andariel
as i understood you are using c not c++ smile.gif
are you writing your program with turbo c or borland c ? because the header you are using is not supported anymore. use #include <iostream> instead. when you include iostream without the h you must incorporate namespaces in your programs as well. add this line after the #incluide -> 'using namespace std;' without the quotations. or you can use a std:: before any cout or endl you use.
enjoy
Dillinja
The best way to learn is to make mistakes!

I should know, I make enough of them in my programming too! hehe biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.