March 6th, 2013, 12:53 AM
I've compiled a program that does some math and asks the user if they want to do another calculation at the end (the users response sets the true/false condition (Y or y for True and any other key for false) for the while statement.
The scanf that reads the users selection is not working, when I have it set to %c for ASCII it just skips that step and ends the program. If I have it set to %d it stops and prompts the user to enter the value, however when a value is entered it goes into a runaway loop.
Not sure if the problem lies with the scanf or somewhere else, any help appreciated.
int main (void)
const float MOW_SPEED = 2;
float length, width;
float mowingArea, mowingTime;
char select = 89;
while(select == 89 || select ==121)
printf("Please enter a length between 10m and 30m: ");
if(length > 10 && length < 30)
printf("Please enter a width between 5m and 20m: ");
if(width > 5 && width < 20)
mowingArea = length * width;
mowingTime = mowingArea/MOW_SPEED;
printf("The time needed is: %.1f\n", mowingTime);
printf("\nPress Y and enter to do another calculation or any other key and enter to exit.\n\n");
printf("Error: Width out of range\n");
printf("Error: Length out of range\n");
March 6th, 2013, 03:30 AM