Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can\'t figure out what is wrong; I don\'t get the correctoutput. include<stdio

ID: 3608548 • Letter: I

Question

I can't figure out what is wrong; I don't get the correctoutput.

include<stdio.h>

int computeStairs(int start1, int end1);

int main(void)
{
   int Start, End;
   double stairCost, totalCost, numStairs;
  
   printf("Please enter the starting elevation ofthe staircase (in feet): ");
   scanf("%d", &Start);
  
   printf("Please enter the ending elevation of thestaircase (in feet): ");
   scanf("%d", &End);
  
   printf("Please enter the cost of each stair:");
   scanf("%lf", &stairCost);
  
   printf(" The staircase will require %fstairs. ", numStairs);
   printf("This will cost $%.2f. ",totalCost);
  
   numStairs = computeStairs(Start,End);
  
   totalCost = numStairs * stairCost;
  
   if(numStairs>=1000)
   {
       printf("You will need a crewof 50. ");
   }
   else if(numStairs<1000 &&numStairs>=100)
   {
       printf("You will need a crewof 25. ");
   }
   else if(numStairs<100)
   {
       printf("You will need a crewof 10. ");
   }  

   return(0);
}

int computeStairs(int start1, int end1)
{  
   return((end1 - start1)/(double)(8/12));
}

EXAMPLE OF CASE :
Please enter the starting elevation of the staircase (in feet):1550
Please enter the ending elevation of the staircase (in feet):2125
Please enter the cost of each stair: 49.95

The staircase will require 862 stairs.
This will cost $43056.90
You will need a crew of 25.


Explanation / Answer

You've got a couple of problems here. First off:    printf(" The staircase will require %fstairs. ", numStairs);    printf("This will cost $%.2f. ",totalCost);       numStairs = computeStairs(Start,End);       totalCost = numStairs * stairCost; If you look here you'll note you're computing the values ofnumStairs and totalCost AFTER you print them out! That can't behelping. You also have a problem here:     return((end1 -start1)/(double)(8/12));This value is always going tobe an issue, because you're dividing by 0. Why are you dividing by0, you ask? It's simple, it comes down to(double)(8/12). In this, the first thing thatoccurs is it is going to divide integer 8 by integer 12. This givesa fractional value and it will round down to 0 because so far it isonly thinking in integers. So you now have(double)(0). NOW the double modifier will beapplied, and it will change from an integer equalling 0 to a doubleequalling 0.0. Not exactly a helpful thing. If you instead call itlike this:     return((end1 -start1)/((double)8/(double)12)); then it will properlyhandle your values. Also, note that since your computeStairs functionis an int, it will be always rounding down the number of stairs tothe nearest integer. Maybe this is what you want because you can'thave a partial stair, but make sure that's how you want to behandling a fractional stair value. Hope this is helpful.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote