Question

In: Computer Science

important : on regular C programming Write a program for a company called Miller Apartments. The...

important : on regular C programming

Write a program for a company called Miller Apartments. The program will ask the user a series of questions and based on their answers, determine if they have apartments that meet their criteria. You must use functions!
Your main() function must call a function named displayMenu() which will print a welcome message and Menu (see sample output). Your main() function will call a function named millerMain() when option 1 is chosen from the menu. millerMain() will then call a function named inputNumberBedrooms() that will ask the user how many bedrooms they would like. You must validate the data inside the function so that they can only choose between 1 and 4 bedrooms. The number of bedrooms is then returned to the millerMain() function.
Your millerMain() function will then call a function named inputNumberBathrooms() that will ask the user how many bathrooms they would like. You must validate the data inside the function so that they can only choose between 1 or 2 bathrooms. The number of bathrooms is then returned to the millerMain() function.
Next, your millerMain() function will ask the user if they would like utilities included in the rent as a Y or N answer.
After you have all of the information from the user, your millerMain() function will send all of the information to a function called determineRent(). The determineRent() function will use a switch statement to determine the base rent given the following:
​1 bedroom à $600.00​2 bedroom à $750.00
​3 bedroom à $900.00​4 bedroom à $1050.00
Additionally, your determineRent() function will use and if statement to add $50 to the base rent if they asked for 2 bathrooms. Lastly, if they choose to include utilities, then your function will add $50.00 for each bedroom.
Once the rent has been determined, your function will return the rent to millerMain().
Your millerMain() function will ask the user to enter in the maximum amount they would be willing to pay for monthly rent. If the rent is more than what they would be willing to pay, you must specify that the rent is more, give them the amount, and ask if they would like to search again using different criteria. If the rent is not more than what they would be willing to pay, then tell them congratulations. You must also let them know how much their rent will be and whether or not it includes utilities. Then you will display the menu again by exiting millerMain() function and returning to the main() function. (See sample output).

Sample Run #1
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​1
How many bedrooms would you like? 1 – 4: 1
How many bathrooms would you like? 1 – 2: 1
Would you like to have utilities included in the rent? Y/N: Y
Enter the maximum amount of rent you are willing to pay: 600.00
Based on your specifications, your total rent of $650.00 is more than your max rent!
Would you like to search using different criteria? Y/N: Y
How many bedrooms would you like? 1 – 4: 1
How many bathrooms would you like? 1 – 2: 1
Would you like to have utilities included in the rent? Y/N: N
Enter the maximum amount of rent you are willing to pay: 600.00
Congratulations! We have an apartment for you to rent!
Your total rent will be $600.00 which does NOT include utilities!
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​0
Thank you for choosing Miller Apartments!
Goodbye.
Sample #2:
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​1
How many bedrooms would you like? 1 – 4: 6
Invalid number of bedrooms, please try again!
How many bedrooms would you like? 1 – 4: 2
How many bathrooms would you like? 1 – 2: 0
Invalid number of bathrooms, please try again!
How many bathrooms would you like? 1 – 2: 1
Would you like to have utilities included in the rent? Y/N: N
Enter the maximum amount of rent you are willing to pay: 800.00
Congratulations! We have an apartment for you to rent!
Your total rent will be $750.00 which does NOT include utilities!
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​0
Thank you for choosing Miller Apartments!
Goodbye.
Sample #3
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​1
How many bedrooms would you like? 1 – 4: 1
How many bathrooms would you like? 1 – 2: 1
Would you like to have utilities included in the rent? Y/N: Y
Enter the maximum amount of rent you are willing to pay: 800.00
Congratulations! We have an apartment for you to rent!
Your total rent will be $650.00 which includes utilities!
----------------------------------------------------------------------
|​​​Welcome to Miller Apartments!​​​​ | ----------------------------------------------------------------------
|​Menu​​​​​​​​​​​ |
|​​New Search:​1​​​​​​​ |
|​​Exit Program:​0​​​​​​​ |
----------------------------------------------------------------------
Enter your choice:​0
Thank you for choosing Miller Apartments!
Goodbye.

Solutions

Expert Solution

// C program to create a program for a company called Miller Apartments based on the series of questions and answers
#include <stdio.h>
#include <stdlib.h>

// function declaration
int displayMenu();
void millerMain();
int inputNumberBedrooms();
int inputNumberBathrooms();
float determineRent(int bedrooms, int bathrooms, char utilityChoice);

int main()
{
int choice;
// loop that continues until user exits
do
{
choice = displayMenu(); // input the choice
if(choice == 1) // user doesn't want to exit
millerMain();

}while(choice != 0);
printf("Thank you for choosing Miller Apartments!\nGoodbye.");
return 0;
}

// function to display the choice and input and return user choice
int displayMenu()
{
int choice;
printf("\n---------------------------------------------------------");
printf("\n|Welcome to Miller Apartments! |");
printf("\n---------------------------------------------------------");
printf("\n|Menu|");
printf("\n|New Search: 1|");
printf("\n|Exit Program: 0|");
printf("\n---------------------------------------------------------");
// input user choice
printf("\nEnter your choice: ");
scanf("%d",&choice);

// validate user choice and re-prompt until valid
while(choice < 0 || choice > 1)
{
printf("Invalid choice, please try again!");
printf("\nEnter your choice: ");
scanf("%d",&choice);
}

return choice;
}

// function to simulate the process to calculating the rent
void millerMain()
{
int bedrooms, bathrooms;
char utilityChoice;
float rent, maxRent ;
char anotherSearch = 'N';

// loop that contains till the user wants
do{
// input number of bedrooms
bedrooms = inputNumberBedrooms();
// input number of bathrooms
bathrooms = inputNumberBathrooms();
// input whether user want to include utilities
printf("Would you like to have utilities included in the rent? Y/N: ");
scanf(" %c",&utilityChoice);
// validate utility choice and re-prompt until valid
while(utilityChoice != 'y' && utilityChoice != 'Y' && utilityChoice != 'n' && utilityChoice !='N')
{
printf("Invalid choice, please try again!");
printf("\nWould you like to have utilities included in the rent? Y/N: ");
scanf(" %c",&utilityChoice);
}

// return rent based on user choice
rent = determineRent(bedrooms, bathrooms, utilityChoice);

// input the maximum rent amount user is willing to pay
printf("Enter the maximum amount of rent you are willing to pay: ");
scanf("%f",&maxRent);

// rent determined > rent willing to pay
if(rent > maxRent){
printf("Based on your specifications, your total rent of $%.2f is more than your max rent!",rent);
// input if user wants to perform another search
printf("\nWould you like to search using different criteria? Y/N: ");
scanf(" %c",&anotherSearch);
// validate user choice and re-prompt until valid
while(anotherSearch != 'y' && anotherSearch != 'Y' && anotherSearch != 'n' && anotherSearch !='N')
{
printf("Invalid choice, please try again!");
printf("\nWould you like to search using different criteria? Y/N: ");
scanf(" %c",&anotherSearch);
}
}
else // rent determined < rent user is willing to pay
{
// display the message
anotherSearch = 'N';
printf("Congratulations! We have an apartment for you to rent!");
printf("\nYour total rent will be $%.2f",rent);
if(utilityChoice == 'y' || utilityChoice == 'Y')
printf(" which includes utilities!");
else
printf(" which does NOT include utilities!");
}
}while(anotherSearch == 'y' || anotherSearch == 'Y');
}

// function to input number of bedrooms and return it
int inputNumberBedrooms()
{
int bedrooms;
// input number of bedrooms
printf("How many bedrooms would you like? 1 - 4: ");
scanf("%d",&bedrooms);
// validate number of bedrooms and re-prompt until valid
while(bedrooms < 1 || bedrooms > 4)
{
printf("Invalid number of bedrooms, please try again!");
printf("\nHow many bedrooms would you like? 1 - 4: ");
scanf("%d",&bedrooms);
}

return bedrooms;
}

// function to input number of bathrooms and return it
int inputNumberBathrooms()
{
int bathrooms;
// input number of bathrooms
printf("How many bathrooms would you like? 1 - 2: ");
scanf("%d",&bathrooms);
// validate number of bathrooms and re-prompt until valid
while(bathrooms < 1 || bathrooms > 2)
{
printf("Invalid number of bathrooms, please try again!");
printf("\nHow many bathrooms would you like? 1 - 2: ");
scanf("%d",&bathrooms);
}

return bathrooms;
}

// function to compute and return the rent based on user choices
float determineRent(int bedrooms, int bathrooms, char utilityChoice)
{
float rent;

if(bedrooms == 1)
rent = 600.00;
else if(bedrooms == 2)
rent = 750.00;
else if(bedrooms == 3)
rent = 900.00;
else
rent = 1050.00;

if(bathrooms == 2)
rent += 50.00;

if(utilityChoice == 'y' || utilityChoice == 'Y')
rent += bedrooms*50.00;

return rent;
}

//end of program

Output:


Related Solutions

PRACTICAL 10 C PROGRAMMING. Question 1 - Reading into a dynamic array. Write a program called...
PRACTICAL 10 C PROGRAMMING. Question 1 - Reading into a dynamic array. Write a program called temperatures01 that reads a (non-empty) sequence maximum daily temperatures. Your program should first ask for the number of temperatures to read and dynamically allocate an array just big enough to hold the number of temperatures you read. You should then read in the elements of the array using a loop. You then should print out the elements of the array in reverse order (from...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt"...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt" (you will have to provide your own when debugging). The text file that is to be opened is formatted a certain way, namely, there is always one integer, one character (representing an operation), another integer, and then a new line character, with spaces between each item. A sample text file is provided below. theNumbers.txt 144 + 26 3 * 18 88 / 4 22...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that...
Programming in C language (not C++) Write a runction derinition for a function called SmallNumbers that will use a while loop. The function will prompt the user to enter integers ine by one, until the user enters a negative value to stop. The function will display any integer that is less than 25. Declare and initialize any variables needed. The function takes no arguments and has a void return type.
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Programming In C Write a program that prints the values in an array and the addresses...
Programming In C Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT