Thursday
July 31, 2014

Homework Help: C Programming

Posted by gnozahs on Wednesday, September 30, 2009 at 5:48pm.

How do you reprompt after the user inputs a wrong number into the program in C Programming? Loop structure?

i.e.
I want my code to do this:

Enter a Compass Heading: 500.7
Please Input a Compass Heading between 0 and 360 Degrees.
Enter a Compass Heading: 360.0

If the user puts a number not in 0 - 360, I want the program to reprompt or start over again.

And where would I put the loop code in?
CODE:
/* Directives */

#include <stdio.h>

int main(void)
{

double heading; /*compass heading in degrees*/

/* Get compass heading */
printf("Enter a Compass Heading: ");
scanf("%lf", &heading);

/* Display equivalent compass bearing */
if (heading < 0.0)
printf("Please Input a Compass Heading between 0 and 360 Degrees.\n", heading);

else if(heading < 90.0)
printf("Compass Bearing: North %.1f Deg East\n", heading);

else if(heading <= 180.0)
printf("Compass Bearing: South %.1f Deg East\n", 180 - heading);

else if(heading <= 270.0)
printf("Compass Bearing: South %.1f Deg West\n", heading - 180.0);

else if(heading <360.0)
printf("Compass Bearing: North %.1f Deg West\n", 360.0 - heading);

else
printf("Please Input a Compass Heading between 0 and 360 Degrees.\n", heading);

/* End Program */
return(0);
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

programming - Write a program which allows user to enter 10 student names and ...
Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
programming - Using Raptor, create a condition loop that will ask the user for ...
C programming - A few questions, all involving "for" loops that I am unsure how ...
programming - Write a C++ code to count the number of characters, words, and ...
C Programming - Write a program that prompts the user to enter a temperature, ...
Programming - Write a pseudocode program that asks the user for an integer ...
Programming logic and design - Design a program that lets the user enter the ...
Computer programming - Sorting is a common operation used in programming. ...
Computer Programing & Logic Design - Submit pseudocode and a flowchart for the ...

Search
Members