Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / How to use this kind of function?

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. How to use this kind of function?
#2561
Posted by: 2003-08-26 14:01:57
I am a primer in c++.
How to use the function like this:
void entry (int i)?
Here is the source code:

#include<iostream>
using namespace std;
int main()
{
   int i=0;
   int phone_book[3]={ 1, 2, 3 };
   void entry (int i) // simple use
   {
      cout<<phone_book<<" "<<"n";
   }
}

I want to use the function : void entry (int i),
and let the program output the first value of the array phone_book,
but it falled.
How to use this kind of function, and what is wrong in my program?

Thank you, and sorry for my poor English.
Message2. Re: How to use this kind of function?
#2562
Posted by: 2003-08-26 14:09:52
Edit:
      cout<<phone_book<<" "<<"n"; should be:
      cout<<phone_book<<" "<<"n";
still falled.
It seems that if I have already send out the post, I can't modify if.
Message3. Re: How to use this kind of function?
#2563
Posted by: 2003-08-26 14:15:11

#include<iostream> 
#include<istream>
using namespace std;
int main()
{
   int i=0;
   int phone_book[3]={ 1, 2, 3 };
   void entry (int i) // simple use
   {
      cout<<phone_book[ i ]<<" "<<"n"; 
   }
}
[code]
cout<<phone_book<<" "<<"n"; should be:
      cout<<phone_book[ i ]<<" "<<"n";
Sorry, when I type the source code, all seem fine, but after I clcik the post button,
some symbols always are missed.

Message4. Re: How to use this kind of function?
#2565
Posted by: guidance 2003-08-26 16:32:34
Only registered user can edit his posts, sorry.
Message5. Re: How to use this kind of function?
#2570
Posted by: 2003-08-27 12:14:58
The problem is solved.
#include<iostream>
#include<istream>
/*
*first, a function can not be defined within another function.
*second, all the funciton except int main() must be called within the function int main().
*/
using namespace std;
void entry(int i); //the form of the function
int main()
{
   int i;
   cout<<"there are three recorders, please entry the value of the recorder number, 0, 1, or 2?n";
   cin>>i;
   entry(i); //call the function entry (int i) within the function main()
}
void entry(int i) //define a function
{
   int phone_book[3]={ 3, 6, 9 };
   cout<<"the recorder"<<i<<"is"<<phone_book<<"n"; 
}
Hope this make sense.

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2022-12-4  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0