GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Feb-2005, 16:11
jheron jheron is offline
New Member
 
Join Date: Feb 2005
Posts: 23
jheron is on a distinguished road

parameter passing?


Hello all
Well here is my story:
I am trying to learn c++ with a sams 12 easy lessons e-book and all the gif's for the examples are missing So I am getting a handle on it but I seem to be confused when it comes to parameter passing I must be missing somthing real easy because this should be a piece of cake ... no??
Here is a simple app I am trying to write to collect skaters names and scores and then give the high,low and average scores. I am using visual c++ to compile it.
CPP / C++ / C Code:
#include <iostream.h>
#include <string.h>


struct Skates
{
	char name[20];
	float score;
};

const int max = 8;	// max number of skaters

int addSkater(Skates& skater, float high, float low, int count);
float getavg(Skates& skaters, int count);


void main()
{
	Skates skaters[max]; // names the struct variable and initializes to 8
	int i, ans, count = 0;
	float avg, high = 0, low = 10;
	
	while (count < max)
	{
		if (addSkater(Skates skaters[count]))
		{
			count++;
		}
		else
		{
			break;
		}
	}
	while(0)
	{
		cout << "What would  you like to do next?" << endl << endl;
		cout << "1. Who has the high score?" << endl << endl;
		cout << "2. Who has the low score?" << endl << endl;
		cout << "3. Whats the average score?" << endl << endl;
		cout << "4. Quit?" << endl;

		switch (ans)
		{
		case(1):
			{
				cout << endl << "The high score belongs to: " << skaters[high] << endl;
				continue;
			}
		case(2):
			{
				cout << endl << "The low score belongs to: " << (skaters[low]) << endl;
				continue;
			}
		case(3):
			{
				avg = (getavg(Skates skaters));
				cout << endl << "The average score is: " << avg << endl;
				continue;
			}
		case(4):
			{
				break;
			}
		}
	}
	cout << "\aThanks for playing!!" << endl;
	return;
}

//***********************************************************************

int addSkater(Skates& skaters, float high, float low, int count)
{
	int i;
	char ans;

	for (i=0; i<max; i++)
	{
		cout << "Would you like to add a skater? [N]o or [Y]es: ";
		cin >> ans; cout << endl;
		cin.ignore(80,'\n'); // skip rubbish

		if((ans == 'y') || (ans == 'Y'))
		{
			cout << "What is the skaters name: ";
			cin.getline(skaters.name,20);
			cout << endl << "Score(0 to 10): ";
			cin.getline(skaters.score);
			cin.ignore(80,'\n'); // skip rubbish

			if(skaters.score > high)
			{
				high = (count + 1); //adds counter of high score to high
			}
			if(skaters.score < low)
			{
				low = (count + 1);
			}

			return 1; //added name ok
		}

		else
		{
			return 0; // no name added
		}
	}
}

//********************************************************************************
float getavg(Skates &skaters, int count) // calculates average score
{
	float ans, tally = 0;		
	int i;

	for(i=0; i<count; i++)
	{
		skaters[i].score += tally;
	}
	ans = (score/count);
	return ans;
}

Here are the errors I am getting:

--------------------Configuration: skaters - Win32 Debug--------------------
Compiling...
skaters.cpp
\skaters.cpp(27) : error C2275: 'Skates' : illegal use of this type as an expression
skaters.cpp( : see declaration of 'Skates'
skaters.cpp(27) : error C2146: syntax error : missing ')' before identifier 'skaters'
skaters.cpp(27) : error C2059: syntax error : ')'
skaters.cpp(2 : error C2143: syntax error : missing ';' before '{'
skaters.cpp(31) : error C2181: illegal else without matching if
skaters.cpp(4 : error C2108: subscript is not of integral type
skaters.cpp(53) : error C2108: subscript is not of integral type
skaters.cpp(5 : error C2275: 'Skates' : illegal use of this type as an expression
skaters.cpp( : see declaration of 'Skates'
skaters.cpp(5 : error C2146: syntax error : missing ')' before identifier 'skaters'
skaters.cpp(5 : error C2059: syntax error : ')'
skaters.cpp(90) : error C2661: 'getline' : no overloaded function takes 1 parameters
skaters.cpp(95) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
skaters.cpp(99) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
skaters.cpp(120) : error C2676: binary '[' : 'struct Skates' does not define this operator or a conversion to a type acceptable to the predefined operator
skaters.cpp(120) : error C2228: left of '.score' must have class/struct/union type

I guess my first question is whats error C2275: 'Skates' : illegal use of this type as an expression telling me? No doubt there is a problem with the way I am trying to pass the parameters??
I know this a lot of crap to look at but I appreciate any and all help on this matter!!
Sincerely Jon
  #2  
Old 27-Feb-2005, 17:45
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Major kudos for using code tags on your first post!!!! Thank you!

Quote:
Originally Posted by jheron
I guess my first question is whats error C2275: 'Skates' : illegal use of this type as an expression telling me?
Assuming line 27 is the following (please place a comment on lines specified so we know what we're looking at)
CPP / C++ / C Code:
if (addSkater(Skates skaters[count]))
... you don't need to specify the structure name on a call. Simply use
CPP / C++ / C Code:
if (addSkater(skaters[count]))
The function definition and prototype make it unnessesary. That change alone will get rid of many of the errors.


Next, your prototype is:
CPP / C++ / C Code:
int addSkater(Skates& skater, float high, float low, int count);
Your definition is:
CPP / C++ / C Code:
int addSkater(Skates& skaters, float high, float low, int count)
Your "corrected" call in main() is:
CPP / C++ / C Code:
if (addSkater(skaters[count]))
See anything missing from the call?
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 27-Feb-2005, 19:54
jheron jheron is offline
New Member
 
Join Date: Feb 2005
Posts: 23
jheron is on a distinguished road
Aaahhh... yes I see severl things missing now that you mention it
Thank you much for taking the time to help me out!! much appreciated
I tried to edit my post above with my corrected code to save space but i cant seem to be able to find the edit button??
Well any ways I think have all my parameter passing figured out please have a look at my code and let me know if I have passed the params correctly.
CPP / C++ / C Code:
#include <iostream.h>
#include <string.h>


struct Skates
{
	char name[20];
	float score;
};

const int max = 8;	// max number of skaters

int addSkater(Skates& skaters, float &high, float &low, int &count);
float getavg(Skates& skaters, int count);


void main()
{
	Skates skaters[max]; // names the struct variable and initializes to 8
	int i, ans, count = 0;
	float avg, high = 0, low = 10;
	
	while (count < max)
	{
		if (addSkater(skaters[count], high, low, count))
		{
			count++;
		}
		else
		{
			break;
		}
	}
	while(0)
	{
		cout << "What would  you like to do next?" << endl << endl;
		cout << "1. Who has the high score?" << endl << endl;
		cout << "2. Who has the low score?" << endl << endl;
		cout << "3. Whats the average score?" << endl << endl;
		cout << "4. Quit?" << endl;

		switch (ans)
		{
		case(1):
			{
				cout << endl << "The high score belongs to: " << skaters[high] << endl;
				continue;
			}
		case(2):
			{
				cout << endl << "The low score belongs to: " << (skaters[low]) << endl;
				continue;
			}
		case(3):
			{
				avg = (getavg(skaters[count], count));
				cout << endl << "The average score is: " << avg << endl;
				continue;
			}
		case(4):
			{
				break;
			}
		}
	}
	cout << "\aThanks for playing!!" << endl;
	return;
}

//***********************************************************************

int addSkater(Skates& skaters, float &high, float &low, int &count)
{
	int i;
	char ans;

	for (i=0; i<max; i++)
	{
		cout << "Would you like to add a skater? [N]o or [Y]es: ";
		cin >> ans; cout << endl;
		cin.ignore(80,'\n'); // skip rubbish

		if((ans == 'y') || (ans == 'Y'))
		{
			cout << "What is the skaters name: ";
			cin.getline(skaters.name,20);
			cout << endl << "Score(0 to 10): ";
			cin >> skaters.score;
			cin.ignore(80,'\n'); // skip rubbish

			if(skaters.score > high)
			{
				high = (count + 1); //adds counter of high score to high
			}
			if(skaters.score < low)
			{
				low = (count + 1);
			}

			return 1; //added name ok
		}

		else
		{
			return 0; // no name added
		}
	}
}

//********************************************************************************
float getavg(Skates &skaters, int count) // calculates average score
{
	float ans, tally = 0;		
	int i;

	for(i=0; i<count; i++)
	{
		skaters[i].score += tally; // add up all the scores and put the result in tally
	}
	ans = (score/count);
	return ans;
}
And the new error log after all my fix ups...
Code:
--------------------Configuration: skaters - Win32 Debug-------------------- Compiling... skaters.cpp skaters.cpp(48) : error C2108: subscript is not of integral type skaters.cpp(53) : error C2108: subscript is not of integral type skaters.cpp(95) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data skaters.cpp(99) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data skaters.cpp(120) : error C2676: binary '[' : 'struct Skates' does not define this operator or a conversion to a type acceptable to the predefined operator skaters.cpp(120) : error C2228: left of '.score' must have class/struct/union type skaters.cpp(122) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data Error executing cl.exe. skaters.exe - 4 error(s), 3 warning(s)
The error "C2108: subscript is not of integral type" refers to these 2 lines:
CPP / C++ / C Code:
		case(1):
			{
				cout << endl << "The high score belongs to: " << skaters[high] << endl; // This one
				continue;
			}
		case(2):
			{
				cout << endl << "The low score belongs to: " << (skaters[low]) << endl; //And This one
				continue;
			}
I am trying to store the index number for the low and high scores so I can display them with this code but I guess there is something wrong with my subscript? What am I missing? When I figure it out it will probly help me with the last 2 errors refering to this line:
CPP / C++ / C Code:
skaters[i].score += tally; // add up all the scores and put the result in tally
Thanks again for any and all help!!
sincerely Jon
  #4  
Old 28-Feb-2005, 02:50
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Hi, Jon.

I'm in a bit of a hurry, so I'll be really quick about this. I hope it's ok.

Quote:
Originally Posted by jheron

I tried to edit my post above with my corrected code to save space but i cant seem to be able to find the edit button??

Indeed, there is a time limit on post editing, mainly because we don't want you to do this!
Just think about it: when someone new arrives on the forum (as a result of a google search, for example) and tries to read your post, he will see Walt giving a solution to a .... correct post! What could anyone understand then? I think this is pretty logical.

Anyway, congrats on the code tags! By using them you make our work easier (which means you get better help).

Quote:
Originally Posted by jheron
The error "C2108: subscript is not of integral type" refers to these 2 lines:
CPP / C++ / C Code:
		case(1):
			{
				cout << endl << "The high score belongs to: " << skaters[high] << endl; // This one
				continue;
			}
		case(2):
			{
				cout << endl << "The low score belongs to: " << (skaters[low]) << endl; //And This one
				continue;
			}
I am trying to store the index number for the low and high scores so I can display them with this code but I guess there is something wrong with my subscript? What am I missing? When I figure it out it will probly help me with the last 2 errors refering to this line:
CPP / C++ / C Code:
skaters[i].score += tally; // add up all the scores and put the result in tally
Thanks again for any and all help!!
sincerely Jon

Well, the problem with printing skaters[high] is that in C/C++ you can't print structs, only their members (if they aren't structs as well ). You probably want something like this:

CPP / C++ / C Code:
cout << endl << "The high score belongs to: " << skaters[high].name << endl;

As for the last errors, you should be careful about what you are working with. You pass a structure by address to the getavg function, but then try to use it as an array. That is why the compiler doesn't know what you mean by skaters[i]. skaters is just a struct here!

I hope this is fine. Try to fix the error about the array passing by yourself. If you don't get that right, please come back for help (BTW, I think you really need a stuct there, and NOT an array)

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 28-Feb-2005, 06:36
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
A few things I found playing with your code:

Quote:
Originally Posted by jheron
CPP / C++ / C Code:
#include <iostream.h>
#include <string.h>

This gives me this error compiling with g++ 3.4.1(cygwin special)

Code:
$ g++ skater.cpp -s -o skater In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.1/../../../../include/c++/3.4.1/backward/iostream.h:31, from skater.cpp:1: /usr/lib/gcc/i686-pc-cygwin/3.4.1/../../../../include/c++/3.4.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

Simply put, in order to correctly add these to the standard namespace lose the '.h'. But that will require you to add a line:

CPP / C++ / C Code:
using namespace std;

Now you have access to the things (in this case cin, cout and endl) from iostream. If you leave out the 'using namespace std;' you should get those named as undeclared. If you don't, turn on some additional warnings from your compiler. For me, when I want to go hog wild, it is -Wall. Then you get some reading when compiling.

Apparently your compiler doesn't care about this one but mine does.
Code:
skater.cpp:18: error: `main' must return `int'

Pretty easy fix to bring you into the '90's (maybe earlier even).
CPP / C++ / C Code:
int main(){

Ok, next victim:
Quote:
Originally Posted by jheron
Code:
skaters.cpp(48) : error C2108: subscript is not of integral type skaters.cpp(53) : error C2108: subscript is not of integral type

Could this be the root of this:
CPP / C++ / C Code:
float avg, high = 0, low = 10;

You are using high to index the array but high is not an integer it is a float.

That's all I have time for this morning. Hope the info is useful.

Mark

EDIT: BTW, I don't see you using anything that needs #include <string>. I commented it out wilh no ill effects but since there are still existing errors I might have missed something.
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #6  
Old 28-Feb-2005, 07:03
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by cable_guy_67
Simply put, in order to correctly add these to the standard namespace lose the '.h'. But that will require you to add a line:

CPP / C++ / C Code:
using namespace std;

Indeed, but if he uses an *older* version of the compiler (lets say he compiles and builds with VC 6) he doesn't need to use the namespace. Of course, the newer headers are prefered, but sometimes one can't upgrade right away.

Quote:
Originally Posted by cable_guy_67
Apparently your compiler doesn't care about this one but mine does.
Code:
skater.cpp:18: error: `main' must return `int'

Pretty easy fix to bring you into the '90's (maybe earlier even).
CPP / C++ / C Code:
int main(){


This doesn't have to do with the outdated compiler, but with the compiler "name". Again, with VC (.NET or earlier) void main will do. You can use the int main version too, it won't mind. Even better - freedom of choice, right?

Just to bee on the safe side, I'm not arguing with your observations, only adding in ;-)

Quote:
Originally Posted by cable_guy_67
Ok, next victim:

Could this be the root of this:
CPP / C++ / C Code:
float avg, high = 0, low = 10;

You are using high to index the array but high is not an integer it is a float.

Wow, can't believe I missed that. You are perfectly right!

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #7  
Old 28-Feb-2005, 21:20
jheron jheron is offline
New Member
 
Join Date: Feb 2005
Posts: 23
jheron is on a distinguished road
Wow thanks guys!! Your time in helping me is greatly appreciated
Well I rewrote my code last night and added a few functions and fixed up all my errors and every thing compiles now with no errors I am however still having problems with my high and low score storing but I am sure i am just over looking some thing simple!

So by the sounds of it there is different syntax for the different versions of c++ (makes sence) I have version 6.0 I thought this was recent but I guess not eh? hehe I bet the book I am using is realy out of date then lol
So what version should I get? (in your opinions)
Well here is my working code if you guys dont mind giving it a looky and mabie give me some constructive critisum(sp) I dont know anybody that can program and therefore only know what I can read on these forums and my book with know examples LOL
CPP / C++ / C Code:
#include <iostream.h>
#include <string.h>


struct Skates
{
	char name[20];
	float score;
};

const int max = 8;	// max number of skaters

int addSkater(Skates& skaters, int &high, int &low, int &count);
float getavg(Skates skaters[max], int count);
void display (Skates& skaters);
void menue (Skates skaters[max], int high, int low, float avg, int count);

void main()
{
	Skates skaters[max]; // names the struct variable and initializes to 8
	int  count = 0, high = 0, low = 10;
	float avg = 0;
	
	while (count < max)
	{
		if (addSkater(skaters[count], high, low, count))
		{
			count++;
		}
		else
		{
			menue (skaters, high, low, avg, count);
			break;
		}
	}

	cout << "\aThanks for playing!!" << endl;
	return;
}

//***********************************************************************

int addSkater(Skates& skaters, int &high, int &low, int &count)
{
	int i;
	char ans;
	float highT = 0, lowT = 10;

	for (i=0; i<max; i++)
	{
		cout << "Would you like to add a skater? [N]o or [Y]es: ";
		cin >> ans; cout << endl;
		cin.ignore(80,'\n'); // skip rubbish

		if((ans == 'y') || (ans == 'Y'))
		{
			cout << "What is the skaters name: ";
			cin.getline(skaters.name,20);
			cout << endl << "Score(0 to 10): ";
			cin >> skaters.score;
			cin.ignore(80,'\n'); // skip rubbish

			if(skaters.score > highT)
			{
				highT = skaters.score;
				high = count; //adds counter of high score to high
			}
			if(skaters.score < lowT)
			{
				lowT = skaters.score;
				low = count;
			}

			return 1; //added name ok
		}

		else
		{
			return 0; // no name added
		}
	}
	return 0;
}

//********************************************************************************
float getavg(Skates skaters[max], int count) // calculates average score
{
	float ans, tally = 0;		
	int i;

	for(i=0; i<count; i++)
	{
		 tally += skaters[i].score; // add up all the scores and put the result in tally
	}
	ans = ((tally-1)/(float)(count+1));
	return ans;
}

//*************************************************************************************
void display (Skates& skaters)
{
	cout << endl << "\tName: " << skaters.name << "\tScore: " << skaters.score << endl;
	return;
}

//**************************************************************************************
void menue (Skates skaters[max], int high, int low, float avg, int count)
{
	int ans = 0;
		while(ans < 4)
		{
		cout << "What would  you like to do next?" << endl << endl;
		cout << "1. Who has the high score?" << endl << endl;
		cout << "2. Who has the low score?" << endl << endl;
		cout << "3. Whats the average score?" << endl << endl;
		cout << "4. Quit?" << endl;


			cin >> ans;

		switch (ans)
		{
		case(1):
			{
				cout << endl << "The high score belongs to: ";
				display(skaters[high]);
				continue;
			}
		case(2):
			{
				cout << endl << "The low score belongs to: ";
				display(skaters[low]);
				continue;
			}
		case(3):
			{
				avg = (getavg(skaters, count));
				cout << endl << "The average score is: " << avg << endl;
				continue;
			}
		case(4):
			{
				return;
			}
		}
		}
}

Thanks again for any and all help!
sincerely Jon
  #8  
Old 28-Feb-2005, 23:39
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by LuciWiz
This doesn't have to do with the outdated compiler, but with the compiler "name". Again, with VC (.NET or earlier) void main will do. You can use the int main version too, it won't mind. Even better - freedom of choice, right?
Wrong! Lucien, I can't believe you said this! void main() is by definition in the C Standard wrong! It's a bad thing to do because some compilers care, one should not use it simply because it works. When you upgrade to a compiler that follows the Standard, you have confusion. "But it's always worked before?!?!?"
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #9  
Old 01-Mar-2005, 01:29
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by WaltP
Wrong! Lucien, I can't believe you said this! void main() is by definition in the C Standard wrong! It's a bad thing to do because some compilers care, one should not use it simply because it works. When you upgrade to a compiler that follows the Standard, you have confusion. "But it's always worked before?!?!?"


Well, as far as I know, this isn't in the C Standard, but it is in the C++ Standard. I may be wrong, but I may be right http://homepages.tesco.net/~J.deBoyn...void-main.html.
I'm not sure about the last ISO version and all. I agree that ALL compilers recognize int main, but not all do the void version. In conclusion you are perfectly right. The other version, standard or no standard, shouldn't be used. Or reccomended. Sorry.

I usually have my main generated by the IDE, and it uses the version you specified. However, I don't mind or care if I see a piece of code using the void main declaration; if I get something like "main must return int" I know what it is all about. Actually, it bothers me more to see unindented pieces of code or other little things like that.

Suggesting it is OK was still wrong and I apologize.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
Last edited by LuciWiz : 01-Mar-2005 at 07:57.
  #10  
Old 01-Mar-2005, 06:50
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Quote:
Originally Posted by LuciWiz
Just to bee on the safe side, I'm not arguing with your observations, only adding in ;-)
Whaaaa, why you little!!!!

Oh wait, I get along well with Lucian. Disclaimer not needed Lucian, I could see where you were going with all that. I do have to agree with Walt though, folks might as well be nudged (prodded, pulled, dragged kicking and screaming, whatever) to use the standards. It makes it easier to get help when anyone can compile, test, recompile and comment. I find it to be an annoyance (granted a small one) when I have to change that darn void to an int (then go back and add a return value to main (instead of just a vanilla return) when it won't hurt to do it from the beginning.

jheron, take note. There are many different people here using many different products to get the same end result (a working executable). Some use IDE's, some (like myself) use a simple editor and console to get there. It is my personal belief (not an implication that you have to do it this way) that working as close to the standards as you can get will be helpful as you learn. As you state in your first post, you are just trying to learn. Well, you have found a good place to do so. You don't have to follow these things that were being discussed but you may at some point move to an environment that is more strict than your current one. Having to 'unlearn' the things that used to work will just act to make it harder on yourself. I found (after finding GIDForums™) that you really do get a better response by using the standards instead of skirting them.

One thing I really (really really) should have mentioned about the .h vs none with namespace is that it was not an ERROR but a WARNING. These are two different things to watch for as you compile your work. Errors must be taken care of, Warnings are things that your compiler/linker are saying, "Hey, there is something here you need to check out." Taking note of these (and perhaps asking why) will help you as you learn.

END RANT.

Quote:
Originally Posted by LuciWiz
Wow, can't believe I missed that. You are perfectly right!

Best regards,
Lucian

Thank you Luci, I was just happy to get a chance to help (as opposed to reading someone else's) for a change.

Now, BACK to OUR regularly scheduled program.

jheron, so far so good, it compiled (after changing the void to int and adding a return 0; to the main) but there are still things to go forward with if you want. For example, when you get to your menue function, try hitting a letter instead of a number. Whoa, what happened?

Since you are already using getline here is a snip of some code I had that deals with this a little differently.

CPP / C++ / C Code:
    string buffer;
    char choice;
    bool cout_test = true;

    cout << "\n\n";
    cout << "===========================================\n";
    cout << "                 TYPE menu                 \n";
    cout << "-------------------------------------------\n";
    cout << "    (P)ersonal    (B)usiness    (O)ther    \n";
    cout << "===========================================" << endl;

    do{
        cout << "TYPE : ";
        getline(cin,buffer);
        buffer = clean_input(buffer,letter_only,1);
    }while( buffer.find_first_of( "pbo") != 0 );
    choice = buffer[0];

NOTE: above uses <string> and clean_input() was something I was playing with a while back(search the forum if interested, it's here somewhere) and also requires the inclusion of <cctype>. For that matter, there are quite a few threads that deal with this topic, seach is your friend.

If you want to take this further, I would be glad to play along. I have only been working with C++ for a short time and can always learn more. Or, just let it go and move on to something else, your call.

Well, my coffee is done so I better get to work. Gonna need those snow boots today. :-)

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing referance and passing pointer Poolan C++ Forum 6 29-Oct-2004 08:18
cannot convert parameter error on DrawTextA ozzytx MS Visual C++ / MFC Forum 1 22-Sep-2004 03:45
Passing VARCHAR to function enomad C Programming Language 5 29-Apr-2004 15:32
need help with passing 3 arrays into a function tommy69 C Programming Language 14 07-Apr-2004 01:22
Help on passing in arrays in functions? nusstu C Programming Language 10 02-Apr-2004 11:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:19.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.