There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 hard drive internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express password printer problem problems ram router security slow software sound trojan usb virus vista windows windows vista windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
C++ Help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Crowe182's Avatar
Junior Member with 14 posts.
 
Join Date: Oct 2003
10-Nov-2003, 08:42 PM #1
C++ Help
I have written a program for class that acts like a phone. It will read a file from my hard driver and then out put if it is a valid number. I have declared a function that passes the value of each digit in the number and then checks that number as valid, how ever it goes in as a char but returns a 0 is valid or -1 if not valid and those are an int. This is the error I get when I invoke the function:

"C:\C++ 2\Lab2.cpp(65) : error C2664: 'to_digit' : cannot convert parameter 1 from 'char' to 'int &'
A reference that is not to 'const' cannot be bound to a non-lvalue"

And this is the code of the function and the additional function I invoked inside.

Code:
char read_dials(ifstream& infile ,char &c1,char &c2,char &c3,char &c4,char &c5,char &c6,char &c7,char &c8)

{

	infile>>c1>>c2>>c3>>c4>>c5>>c6>>c7>>c8;
	if ((to_digit(c1)==-1)||(to_digit(c2)==-1)||(to_digit(c3)==-1)||(to_digit(c4)==-1)||(to_digit(c5)==-1)||(to_digit(c6)==-1)||(to_digit(c7)==-1)||(to_digit (c8)==-1))
		return -1;
	if (c1=='0')
		return -2;
	if ((c1=='5')&&(c2=='5')&&(c3=='5'))
		return -3;
	if (c4 != '-')
		return -4;
	if((c1=='-')||(c2=='-')||(c3=='-')||(c5=='-')||(c6=='-')||(c7=='-')||(c8=='-'))
		return -4;
	if(infile.eof())
		return 0;
}
int to_digit(int& c)
{
	switch (toupper(c))
	{
	case '0':
		c=0;
		return 0;
	case '1':
		c=1;
		return 0;
	case '2': case 'A': case 'B': case 'C':
		c=2;
		return 0;
	case '3': case 'D': case 'E': case 'F':
		c=3;
		return 0;
	case '4': case 'G': case 'H': case 'I':
		c=4;
		return 0;
	case '5': case 'J': case 'K': case 'L':
		c=5;
		return 0;
	case '6': case 'M': case 'N': case 'O':
		c=6;
		return 0;
	case '7': case 'P': case 'R': case 'S':
		c=7;
		return 0;
	case '8': case 'T': case 'U': case 'V':
		c=8;
		return 0;
	case '9': case 'W': case 'X': case 'Y':
		c=9;
		return 0;
	default:
		return -1;
	}
The line where the error is, is on this line:
if ((to_digit(c1)==-1)||(to_digit(c2)==-1).......(c8)==-1))

How do I resolve this error....
AlbertB's Avatar
Distinguished Member with 2,432 posts.
 
Join Date: Nov 2002
Location: Hampshire, UK
11-Nov-2003, 12:24 AM #2
Your function "to_digit" performs its actions on a char which is passed in as 'c'. However you are trying to pass in the address of c - '&c'. Poor thing is confused!


int to_digit(int c) // Note '&' has been removed.
{
switch (toupper(c))
etc



You will also need to make sure that all control paths are returning a value in your "read_dials" function. Add something like:

else
return 1;

to the end as a 'catchall'.
__________________
1. "I make no personal claim to the truth, only the right to seek it, prove it in argument, and to be wrong many times in order to reach it."

2. "We have made a cage of words and placed our God inside, as boys trap a cricket, to make him sing for us alone."

Galileo Galilei
Crowe182's Avatar
Junior Member with 14 posts.
 
Join Date: Oct 2003
11-Nov-2003, 12:32 AM #3
Ok great, that worked...Thanks man, this one has whipped my butt..
One more problem...This error comes up:

"Compiling...
Lab2.cpp
C:\C++ 2\Lab2.cpp(76) : warning C4715: 'read_dials' : not all control paths return a value"

It comes from my read_dials function. What do I need to do to have the return value come up and have the value that is passed to the to_digits function replaced by the switch's case value.
Crowe182's Avatar
Junior Member with 14 posts.
 
Join Date: Oct 2003
11-Nov-2003, 12:35 AM #4
Ok just read the last of your message, where will I put the return value in read_dials?
Crowe182's Avatar
Junior Member with 14 posts.
 
Join Date: Oct 2003
11-Nov-2003, 01:07 AM #5
Great thanks, I got it to work now, and with the help of the debugger.

You guys rock, thanks again!!!!
AlbertB's Avatar
Distinguished Member with 2,432 posts.
 
Join Date: Nov 2002
Location: Hampshire, UK
11-Nov-2003, 10:49 AM #6
Pleased to help Crowe.

If it has solved your problem can you make a point of editing the title of the thread to add on:

" - solved"
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:10 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.