-
Im a newb help!
I am 15 and have been foolin around/ half ..........in with a few compilers. I am taking an actual computer programming class next year and I am really interested in it. I was wondering if any of u can help me. I have read a bunch of recommended books and I need help putting them into action.
I can do really simple basic stuff but I dont know much else.
If you could help me that would be great. If you have aim u can reach me at DragonSlayerTMO.
I just need explanation.
Thanks.
This is a really simple example of what im trying to do tell me why its not working.
Code:
#include <iostream.h> //this is just a simple
//explanation of what it
int main() //is that I am trying to do.
{ //if any could help me that
int a; //would be great!
cout << "testing!" << endl; //Basically I am trying to
cin >> a; //make it so the program does
cout << "testing 2!" << endl; //both functions...i think thats
//the right word anywaz! I cant
return a; //seem to get it to work
}; //correctly. Again any help would
//be glady appreciated!
{ // this is line 13
int b;
cout << "testing b!" << endl;
cin >> b;
cout << "testing b 2!" << endl;
return 0;
}
/* Here is the error it gives me.
On line 13, error c2447: missing function header*/
-
Hi there. Some advice. The message board is here for a reason. There's no reason to randomly harass people over AIM.
-
>If you have aim u can reach me at DragonSlayerTMO.
You should also check back here because most of us won't bother with AIM, just like we won't bother with email. These forums are for public viewing and if your problem isn't important enough for you to come back to check for replies, it isn't important enough for us to expend effort in helping. Just fair warning. :)
>tell me why its not working.
You can't have code blocks at file scope, there must be a function surrounding your code, for example:
Code:
#include <iostream.h>
int f()
{
int a;
cout << "testing!" << endl;
cin >> a;
cout << "testing 2!" << endl;
return f();
};
int main()
{
int b;
cout << "testing b!" << endl;
cin >> b;
cout << "testing b 2!" << endl;
return 0;
}
Granted, that's convoluted, but your intentions with the posted code aren't exactly clear.
-
Here is another try at it, I made the things more respondable hopefully i can get some help.
Code:
#include <iostream.h>
int main()
{
char a;
cout << "whats ur name?" << endl;
cin >> a;
cout << a << " is a good name!" << endl;
return a;
};
int e()
{
int b;
cout << "How old are you?" << endl;
cin >> b;
cout << b << " is a good age!" << endl;
return 0;
}
it still doesnt run the second block in the program. All it says is
whats ur name?
say that i respond John
than it says that J(not john for some reason i need ur help on this one) is a good name
then it ends program
I need help and im sorry for thinkin i can get help i guess thats too much to ask.
But then again maybe there are a thousand peope like me so it gets annoying. ANYWAZ i genuinely need help so ill do it according to ur guys "rules"
pz respond.....
-
>it still doesnt run the second block in the program
Because you don't call the function.
>than it says that J(not john for some reason i need ur help on this one) is a good name
Because you only ask for a single character of input.
Try this:
Code:
int main()
{
char a[50];
cout << "whats ur name?" << endl;
cin >> a;
cout << a << " is a good name!" << endl;
b();
return 0;
};
Just out of curiosity, what "recommended" books have you read, and did you even pay attention while you were reading them? Because both of these problems are a simple and fundamental lack of understanding that the first few chapters of just about any book would alleviate.
-
If you're interested in computer languages, may I recommend HTML? It's a great language that it's very useful in web programming and will teach you a lot about network architecture.
(or something...)
-
Lol my browser f'ed up after i had writin like 4 pages of post anywaz here it is in short
c++ for u ++ (my friend)
beginning programming for dummies (my dad's colleg's computer instructor)
3 online guides including this site
I know a bit of html
mostly i am just unfamiliar with the terms is why i get confused.
heres what i have right now
Code:
#include <iostream.h>
int main()
{
char a[50];
cout << "whats ur name?" << endl;
cin >> a;
cout << a << " is a good name!" << endl;
b(); //LINE 8
return 0;
};
int e()
{
int b;
cout << "How old are you?" << endl;
cin >> b;
cout << b << " is a good age!" << endl;
return 0;
}
errors:
line 8: error C2065: 'b' : undeclared identifier
-
Generally function e would be called by something other than b
-
Code:
#include <iostream.h>
int main()
{
char a[50];
cout << "whats ur name?" << endl;
cin >> a;
cout << a << " is a good name!" << endl;
e ();
return 0;
}
int e()
{
int b;
cout << "How old are you?" << endl;
cin >> b;
cout << b << " is a good age!" << endl;
return 0;
}
ERRORS:
error C2065: 'e' : undeclared identifier
(13) : error C2373: 'e' :
this is the new update
-
Put the code of the e() function above main(), or use a prototype above main:
-
HAAAAH!!!
I got it workin all thanks to u guys. Wow thanks. That really cleared it all up I think i get the basic structure now. Here is the workin one.
Code:
#include <iostream.h>
int e();
int main()
{
char a[50];
cout << "whats ur name?" << endl;
cin >> a;
cout << a << " is a good name!" << endl;
e ();
return 0;
}
int e()
{
int b;
cout << "How old are you?" << endl;
cin >> b;
cout << b << " is a good age!" << endl;
return 0;
}
-
sean_mackrory why? Are you are so constructive.
-
>>Siggy
Make sure that you understand why was your code wrong, why you have to use char[50] instead of char, why you use int e (); before main.
Understanding why is much more important that just knowing the answer.
-
getche(); can also be used, if your program ends as soon as the functions are over.
#include <conio> (on borland)
#include <conio.c> (on dev and others)
-
Also I think your compiler has examples on this kind a program. Anyway on dev-c++ has this kind of source code.