• Need help writing this program! ( FUNCTIONS)
    4 replies, posted
i am trying to write this program to out put my name and age on two separate lines using a void function. i'm stuck! I googled and went through my book and all my notes and i don't know what to do. I need help. here's my code.. i'm new to this so don't tear me apart. #include <iostream> using namespace std; void Print(int, string); int main () { int age; string name; cout << "Please enter your name and age:" << endl; cin >> age >> endl; cin >> name >> endl; Print(age, name); return 0; } //************************************** void Print(age, name) { cout << name << endl; cout << age << endl; }
[code] cin >> age >> endl; cin >> name >> endl; [/code] should be [code] cin >> age; cin >> name; [/code] also, you can use [noparse][code]blah blah[/code][/noparse] tags to post code here
what do you mean by this.. "also, you can use [code]blah blah[/code] tags to post code here" [editline]6th December 2010[/editline] ohhh now i see haha [editline]6th December 2010[/editline] so i changed that part...and i'm still getting an error. says age and name aren't identified print appears to be a function definition.
[code]void Print(int age, string name)[/code] You have to declare their types in the function definition
[code] #include <iostream> #include <string> using namespace std; void Print(int age, string name); int main () { int age; string name; cout << "Please enter your name and age:" << endl; cin >> age; cin >> name; Print(age, name); return 0; } //************************************** void Print(int age, string name) { cout << name << endl; cout << age << endl; } [/code] That... should work.
Sorry, you need to Log In to post a reply to this thread.