In: Computer Science
STATEMENT OF PROBLEM
A developer is building houses in a new neighborhood. She offers 3 house plans: “Montgomery”, “Kettering”, and “Saxon” Although all the windows are the same, each house plan requires a different number of windows: the Montgomery takes 20 windows, the Kettering 15, and the Saxon 12.
She wants you to design a programming solution that will allow her to enter the number of houses she plans to build of each model and have the program display the total number of windows she should order for the neighborhood. She wants to order an extra 1% to allow for breakage and theft. Also, you can only order whole numbers of windows so always truncate the decimal portion of the result and add 1.
Sample screen: (This is an example of what your screen might look like while the program is running.) Note: don't worry if your expected output is off by +/- 1 window. For example, it is OK if the last line in the display below says to order 289, 290, or 291 windows. We haven't covered some of the techniques for resolving rounding issues.
This is my code below. It's an entry-level course and I'm following her instructions the best I can but my code will output '0'. We are programming in C.
/* PREPROCESSOR COMMANDS */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
/* MAIN PROCESSING CONTROL */
int main()
{
/* VARIABLE DECLARATIONS */
double MontgomeryHouses; /* The number of windows in
Montgomery Houses */
double KetteringHouses; /* The number of windows in
Montgomery Houses */
double SaxonHouses; /* The number of windows in
Montgomery Houses */
double WindowsRequired; /* The number of windows
required for all houses */
/* ALGORITHM */
printf("\nHow many Montgomery Houses will you build:
");
fflush(stdin);
scanf("\n%d", &MontgomeryHouses);
printf("\nHow many Kettering houses will you build:
");
fflush(stdin);
scanf("\n%d", &KetteringHouses);
printf("\nHow many Saxon houses will you build:
");
fflush(stdin);
scanf("\n%d", &SaxonHouses);
/* CALCULATE NUMBER OF WINDOWS */
MontgomeryHouses = 20;
KetteringHouses = 15;
SaxonHouses = 12;
WindowsRequired = MontgomeryHouses + KetteringHouses +
SaxonHouses
/* DISPLAY */;
printf("\nYou should order %d",
WindowsRequired);
fflush(stdin);
getchar();
/* PAUSE */
fflush(stdin);
getchar();
return 0;
}
/* END OF FILE */
/*The C++ program that promtps user
to enter double type values and store the values in the variables
and then sum the values. Then print the result on console
output.*/
//main.cpp
/* PREPROCESSOR COMMANDS */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
/* MAIN PROCESSING CONTROL */
int main()
{
/* VARIABLE DECLARATIONS */
double MontgomeryHouses=0; /* The number of
windows in Montgomery Houses */
double KetteringHouses=0; /* The number of windows
in Montgomery Houses */
double SaxonHouses=0; /* The number of windows in
Montgomery Houses */
double WindowsRequired=0; /* The number of windows
required for all houses */
/* ALGORITHM */
printf("\nHow many Montgomery Houses will you build: ");
/*Note : use %lf for format specifier for reading double type
variables
from user*/
scanf("%lf", &MontgomeryHouses);
/*fflush function clear the buffer(temporary storage space)
data*/
fflush(stdin);
printf("\nHow many Kettering houses will you build: ");
/*Note : use %lf for format specifier for reading double type
variables
from user*/
scanf("%lf", &KetteringHouses);
fflush(stdin);
printf("\nHow many Saxon houses will you build: ");
/*Note : use %lf for format specifier for reading double type
variables
from user*/
scanf("%lf", &SaxonHouses);
fflush(stdin);
/* Sum the values stored in the variables and assign the results to
the WindowsRequired*/
WindowsRequired = MontgomeryHouses + KetteringHouses +
SaxonHouses
/* print the WindowsRequired value on console output */;
printf("\nYou should order %lf",
WindowsRequired);
/* PAUSE */
getchar();
return 0;
}
/* END OF FILE */
Sample Output: