Thread: Write a program that will compute the each of the following assignment statements

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    4

    Exclamation Program that converts miles to....

    Just wanted to see if there are any flaws, and if its correctly written.
    Code:
    //Description: Write a program that will convert miles to the
    //             equivalent number of yards, feet, and inches.
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    int main()
    {
    float miles;
    printf("Input the distance in miles ");
    scanf("%f", &miles);
    // 1 mile = 1760 yards
    printf("Value in yards is %f", miles*1760);
    // 1 mile = 5280 feet
    printf("\nValue in feet is %f", miles*5280);
    // 1 mile = 5280 feet * 12 inches
    printf("\nValue in inches is %f", miles*5280*12);
    return 0;
    }
    Last edited by Salem; 05-26-2016 at 12:11 AM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The usual convention is that \n goes on the end of printf lines, not the beginning.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    You might also consider making 1760, 5280, and 12 named constants, and get in the habit of making named constants for so-called "magic" numbers in all of your programs.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 07-09-2012, 08:18 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Replies: 1
    Last Post: 05-26-2006, 08:13 AM
  4. Assignment Statements
    By BlueAerith in forum C++ Programming
    Replies: 2
    Last Post: 02-05-2005, 12:09 PM
  5. Ways to Write IF Statements...
    By mbolthouse in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2001, 06:37 PM

Tags for this Thread