Why am I getting an error

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 673 Views - Last Post: 31 December 2012 - 04:13 PM Rate Topic: -----

#16 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 12:25 PM

Quote

So if anyone can tell me what is not matching up I will appreciate it and if it is matching up

Both your compiler and I have been telling you what is not matching up. But you don't seem to understand that there is a difference between a char and a char array. You need to study the tutorials I provided and if you still don't understand the differences, ask specific questions.

Quote

It is saying NOW : (58): error C2440: 'return' : cannot convert from 'char [4]' to 'char'
1> There is no context in which this conversion is possible


The function tutorials linked in my signature are also very good about how to create and use a function. The only difference between a friend function and a regular stand alone function is that the friend function has access to all members of the class a stand alone function only has access to the public members of your class.

Jim

This post has been edited by jimblumberg: 31 December 2012 - 12:26 PM

Was This Post Helpful? 0
  • +
  • -

#17 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 12:50 PM

Jim I took what you said to heart and am redoing the program to take out char and insert int to see if this will make things any better.

View Postjimblumberg, on 31 December 2012 - 12:25 PM, said:

Quote

So if anyone can tell me what is not matching up I will appreciate it and if it is matching up

Both your compiler and I have been telling you what is not matching up. But you don't seem to understand that there is a difference between a char and a char array. You need to study the tutorials I provided and if you still don't understand the differences, ask specific questions.

Quote

It is saying NOW : (58): error C2440: 'return' : cannot convert from 'char [4]' to 'char'
1> There is no context in which this conversion is possible


The function tutorials linked in my signature are also very good about how to create and use a function. The only difference between a friend function and a regular stand alone function is that the friend function has access to all members of the class a stand alone function only has access to the public members of your class.

Jim


I will study these tutorials thanks Jim
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 01:04 PM

If you are required to use a char array:

Quote

Jim this is what was asked of us in a prior assignment and I just kept it. I would have preferred it to be an integer but they asked for a character. The teacher told us to put an array of 4 so that we could make sure that it accepted up to this many characters.

How will changing things to an int help?

You need to understand the difference between a char, a char* and a char array[]. These are all slightly different, that is why I pointed you to the links about Arrays, Pointers, and Character Arrays. As well as the link for Variables and data types. You need to understand the differences between arrays, pointers and single variables.

Jim

This post has been edited by jimblumberg: 31 December 2012 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

#19 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 01:41 PM

//Lynette Wilkins
//Week 11
//Program that transers a guest from one room to another room
//Lynette Wilkins
//Week 8
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class HotelRoom
{
	friend int Transfer(int,int);
private:
	int room_num; 
	int transroom_num;
	char* guest; //Character pointer,which stores the name of the guest occupying the room
	int room_cap;
	int occup_stat;
	double daily_rt;
	

public:
	HotelRoom(int room, char* g_p, int roomcap, int occup, double rate = 89.00);
	~HotelRoom();
	int Display_Number();  //Displays room number and add the method Display_Guest()
	int Get_Capacity();
	int Get_Status();
	double Get_Rate();
	int Change_Status(int);
	double Change_Rate(double);
	void Display_Guest();
};

HotelRoom::~HotelRoom()
{
	cout << endl<<endl;
	cout << "Guest in room "<<room_num << " has checked out." <<endl;
	delete [] guest;
}

 int HotelRoom::Display_Number()
{
	return room_num;
}

int HotelRoom::Get_Capacity()
{
	return room_cap;
}

int HotelRoom::Get_Status()
{
	
	return occup_stat;
}



int HotelRoom::Change_Status(int occup)
{
	occup_stat = occup;

	if (occup > room_cap)
	{
		return -1;
	}
	else
	
	return occup_stat;
	
}

double HotelRoom::Get_Rate()
{
	return daily_rt;
}

double HotelRoom::Change_Rate(double rate)
{
	daily_rt = rate;
		return daily_rt;
}

int Transfer(int room, int transroom)

{
	
	room = transroom;
	return room;
}

void HotelRoom::Display_Guest()
{
	cout<< guest;
}
int main()
{
	cout<< setprecision(2)
		<<setiosflags(ios::fixed)
		<<setiosflags(ios::showpoint);
	
int room; 
char buffer[100]; //temporarily stores guest name
int roomcap = 4;
int transroom;
int occup;
double rate = 89.00;


cout<<"\nEnter the room number: "<<endl;
cin>>room;

cout<<"\nEnter the amount of guest to occupy this room: "<<endl;
cin>>occup;


cout<<"\nEnter the primary guest name: "<<endl;
cin.ignore();
cin.getline(buffer, 100);

cout<<"\nThe guest has decided to transfer rooms"<<endl;
cout<<"\nEnter the room to transfer the guest to"<<endl;
cin>>transroom;

HotelRoom room1(room, buffer, roomcap, occup, rate); //initialize the object

if (room1.Change_Status(occup) == -1)
{
	cout<<"You have exceeded the room capacity"<<endl;
}
else
{

cout <<"\nThe room number is ";
room1.Display_Number();
cout<<"."<<endl;
cout<<"\nThe name of the primary guest is ";
room1.Display_Guest();
cout <<"."<<endl;
cout<<"\nThe number of guest in the room is "<<room1.Change_Status(occup)<<"."<<endl;
cout<<"\nThe daily rate for room "<<room<< " is "<<room1.Get_Rate()<<"."<<endl<<endl;

cout<<"\nYou have tranferred the guest from room"<<room1.Display_Number()<<"to"<<Transfer(room, transroom)<<endl;
}

cout<<"\nRoom ";
room1.Display_Number();
cout<<" is vacant."<<endl;

system("PAUSE");

	
	return 0;
}





Does this look better??
Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 01:48 PM

It still doesn't compile:

Quote

In function `main':
main.cpp|127|undefined reference to `HotelRoom::HotelRoom(int, char*, int, int, double)'|
||=== Build finished: 1 errors, 0 warnings ===|

Where have you implemented a function with those parameters?


Why are you including the <string> header if you aren't using them. If you are allowed to use std::string it will make writing this program much much easier.

Jim

This post has been edited by jimblumberg: 31 December 2012 - 01:48 PM

Was This Post Helpful? 0
  • +
  • -

#21 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 02:10 PM

View Postjimblumberg, on 31 December 2012 - 01:48 PM, said:

It still doesn't compile:

Quote

In function `main':
main.cpp|127|undefined reference to `HotelRoom::HotelRoom(int, char*, int, int, double)'|
||=== Build finished: 1 errors, 0 warnings ===|

Where have you implemented a function with those parameters?


Why are you including the <string> header if you aren't using them. If you are allowed to use std::string it will make writing this program much much easier.

Jim


I did notice the string after posting it, that is removed and I did notice that I left guest name there and that is removed. I am just needing to declare room_num now and we will see what happens.
Was This Post Helpful? 0
  • +
  • -

#22 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 02:32 PM

Jim,

Please explain to me why it is stating room_num is undeclared when it is right here.


int room_num; 



Was This Post Helpful? 0
  • +
  • -

#23 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 02:42 PM

Where is it stating that room_num is not declared? The only error I got with your program was that you didn't have constructor with the proper number of parameters.

Jim
Was This Post Helpful? 0
  • +
  • -

#24 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 03:51 PM


//Lynette Wilkins
//Week 11
//Program that transers a guest from one room to another room
//Lynette Wilkins
//Week 8
#include <iostream>
#include <iomanip>


using namespace std;

class HotelRoom
{
	friend int Transfer( HotelRoom&, int);
private:
	int room_num; 
	int transroom_num;
	int room_cap;
	int occup_stat;
	double daily_rt;
	

public:
	HotelRoom(int room, int roomcap, int occup,  int transroom, double rate = 89.00);
	~HotelRoom();
	int Display_Number();  //Displays room number and add the method Display_Guest()
	int Get_Capacity();
	int Get_Status();
	double Get_Rate();
	int Change_Status(int);
	double Change_Rate(double);
	void Display_Guest();
};

HotelRoom::~HotelRoom()
{
	cout << endl<<endl;
	cout << "Guest in room "<<room_num << " has checked out." <<endl;
}

 int HotelRoom::Display_Number()
{
	return room_num;
}

int HotelRoom::Get_Capacity()
{
	return room_cap;
}

int HotelRoom::Get_Status()
{
	
	return occup_stat;
}



int HotelRoom::Change_Status(int occup)
{
	occup_stat = occup;

	if (occup > room_cap)
	{
		return -1;
	}
	else
	
	return occup_stat;
	
}

double HotelRoom::Get_Rate()
{
	return daily_rt;
}

double HotelRoom::Change_Rate(double rate)
{
	daily_rt = rate;
		return daily_rt;
}

int Transfer(HotelRoom& room_r1, int transroom)

{
	//if guest transfers to different hotel room, room is vacant and transroom is now occupied
	room_r1.room_num = room_r1.transroom_num;
	
	

	return rooms_num;

}


int main()
{
	cout<< setprecision(2)
		<<setiosflags(ios::fixed)
		<<setiosflags(ios::showpoint);
	
int room = 0; 
int roomcap = 4;
int transroom;
int occup;
double rate = 89.00;


cout<<"\nEnter the room number: "<<endl;
cin>>room;

cout<<"\nEnter the amount of guest to occupy this room: "<<endl;
cin>>occup;


cout<<"\nThe guest has decided to transfer rooms"<<endl;
cout<<"\nEnter the room to transfer the guest to"<<endl;
cin>>transroom;

HotelRoom room1(room,roomcap, occup, transroom, rate ); //initialize the object

if (room1.Change_Status(occup) == -1)
{
	cout<<"You have exceeded the room capacity"<<endl;
}
else
{

cout <<"\nThe room number is ";
room1.Display_Number();
cout<<"."<<endl;
cout<<"\nThe name of the primary guest is ";
room1.Display_Guest();
cout <<"."<<endl;
cout<<"\nThe number of guest in the room is "<<room1.Change_Status(occup)<<"."<<endl;
cout<<"\nThe daily rate for room "<<room<< " is "<<room1.Get_Rate()<<"."<<endl<<endl;



cout<<"\nYou have tranferred the guest from room"<<room1.Display_Number()<<"to"<<Transfer(room1,transroom)<<endl;
}

cout<<"\nRoom ";
room1.Display_Number();
cout<<" is vacant."<<endl;

system("PAUSE");

	
	return 0;
}



Put this in your compiler
Was This Post Helpful? 0
  • +
  • -

#25 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 03:58 PM

Why? What is wrong with your code? If you have errors post the complete error message exactly as they appear in your development environment. These messages have important information to aid in locating and fixing the errors. But I suggest you check your spelling, C/C++ is very particular about spelling being the same.

Jim
Was This Post Helpful? 0
  • +
  • -

#26 llwilkins  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 06-November 12

Re: Why am I getting an error

Posted 31 December 2012 - 04:07 PM

(92): error C2065: 'room_num' : undeclared identifier

Here is the error
Was This Post Helpful? 0
  • +
  • -

#27 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: Why am I getting an error

Posted 31 December 2012 - 04:13 PM

I bet the error says "rooms_num" not "room_num".

Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2