-- If you know of a shorter way to do this .. post away plz
-- the nightscost and totalcost cause erros ( call to undefined function )
-- get a fair amount of warnings, but i can live with warnings

#include <iostream>
#include "Thefunctions.cpp"
using namespace std;


int main()
{
// function calls
void gettype1();
int choice;
double nights;
double tax;
double totalcost = 0.0;
double nightscost = 0.0;

// Displays all of the Motels cost information
cout << "Floor's 1-5 are $45.00 for a Single, $60.00 for a Double, and $130.00 for a Suite" << endl;
cout << "Floor's 6-11 are $55.00 for a Single, $72.00 for a Double, and $215.00 for a Suite" << endl;
cout << "The top floor rates are, $120.00 for a Double, and $350.00 for a Suite. We do not offer Single rooms on the 12th floor" << endl;

// Prompts user to enter the reservation information 
cout << "Enter the type of room you wish for, 1(Single), 2(Double), 3(Suite):" << endl;
cin >> room;
cout << room << endl;

cout << "Enter which floor desired (1-12):" << endl;
cin >> choice;
cout << choice << endl;

cout << "Enter the number of nights you will be staying:" << endl;
cin >> nights;
cout << nights << endl;

// GET CALL TO UNDEFINED FUNCTIONS ON THESE TWO(nightscost & totalcost)
nightscost = nightsfunction(nights);
totalcost = totalfunction(totalcost, tax);

// Dispays the users' input
cout << "The nightly cost would be "<< nightscost << endl;
cout << "The total price would be " << totalcost << endl;

return 0;
}


-- FUNCTIONS 
-- would have used a case statement but cant remember exact syntax
-- so i ended up abusing if statements /shrug
#include <iostream>
using namespace std;

int room;
int floor;

void gettype1(int choice)
{
if(room = '1' && floor <= 5)
{
rcost = 50;
}
if(room = '1' && floor >= 6 && floor <= 11)
{
rcost = 65;
}
if(room = '1' && floor = 12)
{
rcost = 150;
}
return;
}

{
if(room = '2' && floor <= 5)
{
rcost = 55;
}
if(room = '2' && floor >= 6 && floor <= 11)
{
rcost = 72;
}
if(room = '2' && floor = 12)
{
rcost = 215;
}
return;
}

if(room = '3' && floor <= 5)
{
cout << "Not available, we apologize." << endl;
}
if(room = '3' && floor >= 6 && floor <=11)
{
rcost = 120;
}
if(room = '3' && floor = 12)
{
rcost = 350;
return;
}
double nightsfunction(int nights, int room, double tax)
{
if(nights >= 4)
		{stay = (nights * .10);}
				
}
double totalfunction(double totalcost, double tax)
{
		double totalcost;
		double stay;
		tax += 1;
		totalcost = (stay + rcost) * tax;
cout << "Your cost is " << totalcost << endl;
return totalcost;

}

Recommended Answers

All 9 Replies

>>get a fair amount of warnings, but i can live with warnings
You are crazy if you do because most warnings are really errors. Fix them.

line 2: never ever at any time should you include one *.cpp in another like that. Compile them separately and link them together. That's what compilers do.

>>get a fair amount of warnings, but i can live with warnings
You are crazy if you do because most warnings are really errors. Fix them.

line 2: never ever at any time should you include one *.cpp in another like that. Compile them separately and link them together. That's what compilers do.

.cpp is what you have to save the file as ..... one is the main page and the #include functions.cpp is on a notepad doc. ----- the .cpp is called from a diff file

>>#include "Thefunctions.cpp"
It doesn't matter how you wrote it -- never ever do that! No excuses.

What compiler are you using anyway.

.cpp is what you have to save the file as ..... one is the main page and the #include functions.cpp is on a notepad doc. ----- the .cpp is called from a diff file

Nope, sorry, but it just isn't supposed to work like that. If you're using an IDE, add all source files to your project. If you're using a command line compiler, read the documentation on the flags needed to compile multiple source files. Never #include a .cpp file.

ok nvm mind....i've been programming .cpp files for a year. in school for it. in every program that i've written in class we had to #include functions.cpp... this is C++ IDE, borland compiler. The .cpp isnt even the problem with the program, if i take out the two function calls that cause the error, then the program runs fine. I do need those two function calls though. Its not all on one page. The functions are on a completely different page, hence the #include functions.cpp. My professor makes us use modulation(#include .cpp files) Thank you for your time though

>My professor makes us use modulation(#include .cpp files)
Then your professor's teaching you wrong.

Although I did try putting my code through my compiler, and you have all sorts of other problems:
- You never declared 'rcost' or 'stay'
- You're using quotes around your integer values, which is wrong.
- There's extra braces lying around for no apparent reason
- In totalfunction(), you redeclared 'totalcost'
- You're not calling nightsfunction() with the right number of parameters (which is likely the cause of the undefined function problem)

-- ok i rewrote the program but i am still having some trouble with it.
-- if you know a fix would you let me know plz?

#include <iostream>
using namespace std;


int main()
{

int room =0;
double rcost = 0;
double totalcost = 0;
double totalbill = 0;
int nights;
double stay = 0;
int floor;

// Displays all of the Motels cost information
cout << "Floor's 1-5 are $45.00 for a Single, $60.00 for a Double, and $130.00 for a Suite" << endl;
cout << "Floor's 6-11 are $55.00 for a Single, $72.00 for a Double, and $215.00 for a Suite" << endl;
cout << "The top floor rates are, $120.00 for a Double, and $350.00 for a Suite. We do not offer Single rooms on the 12th floor" << endl;

// Prompts user to enter the reservation information 
cout << "Enter the type of room you wish for, 1(Single), 2(Double), 3(Suite):" << endl;
cin >> room;

cout << "Enter which floor desired (1-12):" << endl;
cin >> floor;

cout << "Enter the number of nights you will be staying:" << endl;
cin >> nights;

 if(room == 1) 
 if(floor <= 5)
rcost = 50;
cout << rcost;

else if
if(room == 1)
if(floor <= 11) 
rcost = 65;
cout << rcost;

else if
if(room == 1)
if(floor = 12)
rcost = 150;
cout << rcost;

else if
if(room == 2)
if(floor <= 5)
rcost = 55;
cout << rcost;

else if
if(room == 2)
if(floor >= 6)
rcost = 150;
cout << rcost;

else if
if(room == 2)
if(floor = 12)
rcost = 215;
cout << rcost;

else if
if(room = 3) 
if(floor <= 5)
cout << "Not available, we apologize." << endl;
cout << rcost;

else if
 if(room == 3)
if(floor > 12)
rcost = 120;
cout << rcost;

else if
if(room = 3)
if(floor = 12)
rcost = 350;
cout << rcost;

 cout << "The total price would be " << '$' << rcost << endl;
// Does the math for the total of room / floor / nights cost
double tax = .10;
    if(nights >= 4)
		{stay = (nights * tax) + nights;
        totalbill = (stay * rcost) + rcost;}
       cout <<stay;
    return totalbill;
        }

lines 36 and 37 -- similar lines that follow too. Too many if's -- should only have one 'if'. You are also missing the braces { and } when more than one line within the if statement

else 
if(room == 1)
{
    if(floor <= 11) 
    {
            rcost = 65;
           cout << rcost; 
    }
}
else 
// etc. etc

You can shorten up the above a little bit like this:

else 
if(room == 1 && floor <= 11)
{
      rcost = 65;
      cout << rcost; 
}
else 
// etc. etc

Thank you, I re-coded it to that way. Will have to wait till tommorrow to use a compiler

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.