Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-09-2006, 10:39 AM   #1 (permalink)
choseone437
Registered User
 
Join Date: Mar 2006
Posts: 1
choseone437 is on a distinguished road
help

im new here im wonder if anyone canth help mevoid find(){
Code:
void find()
{
  cout<<"Enter id number"<<endl;
  cin>>id;
  for(i=0;i<2;i++)
  {
    if(id==employees[i]->getID())
    {
      cout<<"Salary is $";
      cout<<employees[i]->getSalary<<endl;
    }
  }//end of for 
}//end of function
the code above is a find function that is suppose to return the employees salary from the array but if some one enters a id that doesnot exist the function is to return -1 cant any one tellm e to that thanks in advance

Last edited by redhead; 03-09-2006 at 11:37 AM.
choseone437 is offline   Reply With Quote
Old 03-09-2006, 11:38 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Code:
int find()
{
  cout<<"Enter id number"<<endl;
  cin>>id;
  for(i=0;i<2;i++)
  {
    if(id==employees[i]->getID())
    {
      cout<<"Salary is $";
      cout<<employees[i]->getSalary<<endl;
      return employees[i]->getSalary; // object found
    }
  }//end of for 
  return -1; // nothing found
}//end of function
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-10-2006, 01:58 PM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
This part doesn't belong that function:
Code:
cout<<"Salary is $";
cout<<employees[i]->getSalary<<endl;
Leave it out and implement it outside. Functions need to do one thing only.
Just a tip .
__________________

Last edited by Valmont; 03-12-2006 at 11:01 AM.
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting