I would agree with Vernon. AD helped me out quite a bit in this respect. What you can do is create a separate cpp file for your functions if you don't want to do it on the same "page" as your main. The way I have been doing it (yes it may be going too far) is to create a header file:
myprogramheader.h
in here are my includeguards
in here are my prototypes
#ifndef NAMEINP_H
#define NAMEINP_H
char getlast( char lastName[] , int maxin);
char getfirst( char firstName[] , int maxin);
char getmid( char midName[] , int maxin);
void punchmeinthehead();
#endif
Then I create a cpp file to hold my functions
myprogramfunctions.cpp
in here are all the functions I want to call in main
(Toggle Plain Text)
#include "nameinp.h"
#include <iostream>
#include <string.h>
using namespace std;
//Input last name
void getlast( char lastName[] , int maxin)
{
cout << " Please enter your last name up to 15 characters " << endl;
cin.getline(lastName, maxin, '\n' );
cin.ignore (cin.rdbuf()->in_avail(), '\n');
}
//Input first name
void getfirst( char firstName[] , int maxin)
{
cout << " Please enter your first name up to 15 characters " << endl;
cin.getline(firstName, maxin, '\n' );
cin.ignore (cin.rdbuf()->in_avail(), '\n');
}
//and so on with the other individual functions
Then I create a cpp file for my main
mymainprogram.cpp
function call
function call
function call
void main()
{
//declarations
const int maxin = 16;
char lastName[maxin];
char firstName[maxin];
char midName[maxin];
//function calls
getlast(lastName, maxin);
getfirst(firstName, maxin);
getmid(midName, maxin);
punchmeinthehead();
}
I know it all seems a bit separated and more effort than necessary for what you are doing, but it works really well for a code a little compile a little mentality. Not to mention once your functions are correct and you know they are correct, all you have to deal with is your main.
My errors have really all been small ones that I've blown out of proportion with my own inexperience, but with the help of these folks (AD, Sarehu, Vernon, Vij) it's getting me thinking more about how the code actually works and the theory behind it. Separating all this helps me work with my functions, pass them around, and get used to doing things a little at a time. Hope it helps