Search code examples
cstdio

Issue with some simple logic and getting something to print C++ HouseWindowsLab


Please Help. This simple program is suppose to calculate users inputs for how many of each house they want. Multiply it by the windows each house adds. And apply 1% more windows to the total for spares. Why isn't the spare part working?

/*************************************
* PROGRAM: WindowCalculator
* AUTHOR: Matthew Nickles
* DATE: 9/6/2018
* NOTES: This is for educational purposes, the program calculates
* how many windows for each house plan a city builder would get.
**************************************/

/* PREPROCESSOR COMMANDS */
#include <stdio.h>


/* MAIN PROCESSING CONTROL */
int main()
{
/* VARIABLE DECLARATIONS */
int MontgomeryHouses; /*20 Windows per a house*/
int KetteringHouses; /*15 Windows per a house*/
int SaxonHouses; /*12 Windows per a house*/
int TotalWindows; /*Total calculation of all windows*/
int SpareWindows; /*How many spare windows if you wanted 1% of total*/ 

/* WINDOWS PER HOUSE ALGORITHM */
printf("\n How many Montgomery Houses do you wish to build? They have 20             windows. ");
scanf("\n%d", &MontgomeryHouses);
fflush(stdin);

printf("\n How many Kettering Houses do you wish to build? They have 15 windows. ");
scanf("\n%d", &KetteringHouses);
fflush(stdin);

printf("\n How many Saxon Houses do you wish to build? They have 12 windows. ");
scanf("\n%d", &SaxonHouses);
fflush(stdin);

/* CALCULATE TOTAL WINDOWS*/
TotalWindows = (MontgomeryHouses * 20) + (KetteringHouses * 15)
        + (SaxonHouses * 12);
SpareWindows = TotalWindows * 0.01;
/* DISPLAY OUTPUT*/
printf("The spare windows needed &d are windows.\n",SpareWindows);
fflush(stdin);  
printf("\nThe total amount of windows needed for all houses are %d windows.\n",TotalWindows);
fflush(stdin);



return 0;
}
/* END OF PROGRAM */

Solution

  • Your logic is totally fine. It is just a tiny syntax error. In this line:

    printf("The spare windows needed &d are windows.\n",SpareWindows);

    &d should be replaced by %d.

    I think you just overlooked it, because the other parts are perfect.