This program will take in data related to hotel room rates for one week and crea
ID: 3801257 • Letter: T
Question
This program will take in data related to hotel room rates for one week and create a report for selected hotels.
Write a complete C program that performs the following tasks:
Declare one 1-D array of char that can hold up to 20 characters.
Each element of this array corresponds to one hotel, indicating whether its data will be displayed or not.
Declare one 2-D array of double that can hold up to 20 rows and 7 columns.
Each row of this array corresponds to one hotel. Each hotel will have 7 values corresponding to their lowest room rate each night, Sunday night through Saturday night.
Ask for the number of hotels. You do not need error checking here; assume the input will be in the range from 1 to 20.
For the number of hotels, read in one character, and store it to the char array in order of entry. These characters will be 'y' or 'n'.
For the number of hotels, read in 7 double values and store them to the 2-D array by rows.
Finally, print the hotel report:
For each hotel
Check whether that hotel's prices should be printed (y/n from the char array).
If y, print that hotel's data with exactly one space between prices
If n, don't print anything (skip to the next hotel).
Notes: - Prices are to be printed with 2 decimal places. - Use the first line below as the prompt to start, and the second line as the label for each line of output in your program:
Explanation / Answer
#include <stdio.h>
int main(void)
{
int n;
char displayHotel[20]; //declaration of 1-D array
double rates[20][7]; //declaration of 2-D array
printf("How many Hotels? ");
scanf("%d", &n); //Prompt for no. of hotels
for(int i = 0; i < n; i++)
{
int j = i;
printf("Want to display data for hotel %d.",j+1);
scanf(" %c", &displayHotel[i]); //Prompt for for displaying prices y/n.
}
for(int i = 0; i < n; i++)
{
int k = i;
printf("Enter prices Sun - Sat for hotel %d. ", k+1); //Prompt for entering prices for different hotels.
for(int j = 0; j < 7; j++)
{
scanf("%lf", &rates[i][j]);
}
}
printf(" Prices Sun - Sat: "); //displaying prices
for(int i = 0; i < n; i++)
{
if(displayHotel[i] == 'y')
{
int k = i;
printf("Hotel %d. ", k+1);
for(int j = 0; j < 7; j++)
{
printf("%0.2lf ", rates[i][j]);
}
}
printf(" ");
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.