I need help i am not sure if i am on the right track.

i have to write a program to calculate the night of nights someone has to stay and what size bed they want. than i have to give a total of cost plus 6% sales tax. her is what i have so far.. i am getting a compiling error at the start of the first "if" statement.
please help

#include <iostream> // required to perform C++ stream I/O
#include <string> //requied to perform string varibles
#include <iomanip> //requied to perform parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

int main() //requied for every program;should return integer result code
{
char nights; // store number of nights
char size; // store room type
char response='y'; //store response


while (response!='n' && response!='N') //start of while statement does not run if n/N is typed
{
    cout<< "Please enter the numbers of nights you would like to stay:";//propomt for number of nights to stay

    cin>>nights; //store the number of nights in variable nights

    if (nights<='30') && (nights!='0') // response can not be more than 30 or less than 0

    {

    cout<<"please enter K for king size bed or Q for queen size bed:";// prompt for bed size

    cin>>size;// store the size k or q

    }
        if (size=='Q')//  if Q than true

        {

        cout<<"n/Total: $" <<nights * 100.00; // output the number of nights times $100.00
        }

    else
        if (size=='K')// if K than true

        {

        cout<<"n/Total: $" <<nights * 150.00;// output the number of nights times $150.00

        }
    else (size!='K') && (size!='Q')// if k and q are false than continue

        {
            cout<<"number of nights must between 1-30";// output error
        }

    cout<<"Would you like to enter additional nights (y = yes, n = no)?";// prompt for additional nights

            cin>>response;// output response

            cout<<endl;//add space to make easier to read

}//end while
   cout << "\n"; // insert newline for readability






   return 0; // indicate that program ended successfully

} // end function main

Recommended Answers

All 10 Replies

>>if (nights<='30') && (nights!='0')

Badly formed. You need more parentheses. And a single character can not hold more than one numeric digit, so probably need to test against integers instead of charcters. if ((nights<=30) && (nights!=0))

Also... Please use code tags.

can you use && with integers? i didn't think you could? not should what you mean by code tags? very very new to C++

Where are you using && with integers?

Code tags are described here.

i got it to compile but I think my if statement is incorrect. iF the user picks K it doesn't go the else and do the calculations for K? help is there a better way to write what i want to do?:(

#include <iostream> // required to perform C++ stream I/O
#include <string> //requied to perform string varibles
#include <iomanip> //requied to perform parameterized stream manipulators

using namespace std; // for accessing C++ Standard Library members

int main() //requied for every program;should return integer result code
{
int nights; // store number of nights
char size; // store room type
char response='y'; //store response
	

while (response!='n' && response!='N') //start of while statement does not run if n/N is typed
{
	cout<< "Please enter the numbers of nights you would like to stay:";//propomt for number of nights to stay

	cin>>nights; //store the number of nights in variable nights

	if ((nights<=30) && (nights!=0)) // response can not be more than 30 or less than 0

	{

	cout<<"please enter K for king size bed or Q for queen size bed:";// prompt for bed size

	cin>>size;// store the size k or q

	}
		if (size=='Q')//  if Q than true

		{

		cout<<"n/Total: $" <<nights * 100.00<<endl; // output the number of nights times $100.00

		}

	else
		if (size=='K')// if K than true

		{

		cout<<"n/Total: $" <<nights * 150.00<<endl;// output the number of nights times $150.00

		}


	cout<<"Would you like to enter additional nights (y = yes, n = no)?";// prompt for additional nights

			cin>>response;// output response

			cout<<endl;//add space to make easier to read
   
}//end while
   cout << "\n"; // insert newline for readability






   return 0; // indicate that program ended successfully

} // end function main

Are you sure that your user isn't picking k instead of K?

lol that is what i did -- ok i have to put in something to stop that from happening. i think i can do that

i am still having a problem with the first if statement-- if i enter 31 i want it fail and it should cout an error but it is not failing? can i write my first if statement better? i want it to only accept 1-30

Buddy I don't get it! You are supposed to do it as home work as I understand it you have to ask the user to enter the number of nights to stay the Bed size then out put the prize right?

Here is my code:

#include <iostream>

#define MIN_NIGHTS 0
#define MAX_NIGHtS 30
int main(){

// Global
char bedsize = ' ';
int price = 0;
int nights = 0;

do{
int choice = 0;
cout << "Enter nights to stay\n";
cin >> nights;
if(nights < MIN_NIGHTS || nights > MAX_NIGHTS)
return 0; // Or ptint error
cout << "Enter bedsize K or Q(king queen)\n";
cin >> bedsize;
double bedprice = 0;
if(bedsize == 'Q')
bedprice = 100.0;
else if(bedsize == 'K')
bedprice = 150.0;
else; // Error msg
price = (double)(nights * bedprice) + ((nights * bedprice) * 0.6);
cout << "Total " << price;
}while(choice != 'E')
}

#
if ((nights<=30) && (nights!=0)) // response can not be more than 30 or less than 0

Or else what? where's your else statement? (nights != 0) does not restrict to positive integers either. How about (nights > 0). Then an else statement to return 1 or just print an error message to the screen if ((nights <= 30) && (nights > 0)) is false.

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.