This is my first day of C++ and I was wondering how to get multiple functions in a C++ program. Any help would be appreciated. Here is my source.
ThanksCode:#include <iostream> using namespace std; int main() { char number; cout << "Please input a value\n"; cin >> number; cout << " You selected: " << number; second(); // This should work in a C program, how do I do it in C++ system("PAUSE"); return 0; } int second() // This is where I run into problems { char number; cout << "Please select another value..."; cin >> number; cout << "You selected: " << number; }
Last edited by nicckk; 01-22-2011 at 10:12 AM.
You have to declare second() before you can call it.
Code:// Value selector // Nick Dichev 2009 #include <iostream> using namespace std; int second() ; int main() { char number; cout << "Please input a value\n"; cin >> number; cout << " You selected: " << number; second(); // This should work in a C program, how do I do it in C++ system("PAUSE"); return 0; } int second() // This is where I run into problems { char number; cout << "Please select another value..."; cin >> number; cout << "You selected: " << number; }
Thanks Winged, that worked. But the compiler then told me I needed a semi-colon before the int main(). I plugged it in and it worked fine. Can you describe why? I thought that a semi-colon ended a line of code?
Thanks
declares a function, and must end with a semi-colon, just like any other declaration (such as intCode:int second();).Code:i;
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks