Question

In: Computer Science

A program written in C that asks for the distance to be entered and then prints...

A program written in C that asks for the distance to be entered and then prints the fare

A transportation company has the following rates

  1. For the first 100 miles                                                       20 cents a mile
  2. For the next 100 miles                                                       a) + 10 cents per mile over 100 miles
  3. For the next 100 miles                                                       b) + 8 cents per mile over 200 miles
  4. more than 300 miles                                                          c) + 5 cents per mile over 300 miles

Write a program that asks for the distance to be entered and then prints the fare

Check your answers       50 miles should cost    $10
150 miles should cost    $25
300 miles should cost    $38

Solutions

Expert Solution

CODE :

OUTPUT :

Raw_Code :

#include<stdio.h>           //including standard library
int main(){
   int miles;
   float cents,dollors;       //declaring required variables
   printf("Enter Number of Miles : ");      
   scanf("%d",&miles);               //taking miles as input
   if(miles<=100){                   //if it is first 100 miles
       cents = miles * 20;
   }
   else if(miles > 100 && miles <= 200){       //if it is less than 200 miles
       cents = (100 * 20) + ((miles - 100) * 10);
   }
   else if(miles > 200 && miles <= 300){           //if it is less than 300 miles
       cents = (100 * 20) + (100 * 10) + ((miles - 200) * 8);
   }
   else if(miles > 300){           //if it is greater than 300 miles
       cents = (100 * 20) + (100 * 10) + (100 * 8) + ((miles - 300) * 5);
   }
   dollors = cents / 100;           //converting cents to dollors
   printf("The Transport Fare for %d miles is : $%.2f\n",miles,dollors);       //printing required output
   return 0;
}

**********Comment me for any Queries and Rate me up*************


Related Solutions

Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Code in C ++ that asks the user for an integer and that prints whether or...
Code in C ++ that asks the user for an integer and that prints whether or not the number is divisible by three in the integers. If the number is not divisible by three, the program must write a message indicating what the remainder is obtained by dividing the number by three.
Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a program that asks the user for an integer and then prints out all its...
Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop.in c++
User asks you to develop a program that calculates and then prints interest earned on a...
User asks you to develop a program that calculates and then prints interest earned on a bank balance. Program should print interest earned for the same balance when interest is accumulated annually, semiannually and quarterly. I need the C++ code!
Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a...
Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) . Don't use function. Example 1: Input width: 16 Input height: 11 Shape: *** *** *** *** *** *** *** *** *** *** *** * *** *** * *** *** * *** *** *** *** *** *** *** *** *** *** *** * *** *** *...
only using C (not C++) Implement a program that counts the words and prints their frequencies....
only using C (not C++) Implement a program that counts the words and prints their frequencies. In particular, the program extracts “words” from one or more text files, from a pipe, or from the console, and prints to the console the list of words found and their associated frequencies. Note that your project submission is restricted to only using the following system calls: open(), close(), read(), write(), and lseek() for performing I/O. You are allowed to use other C library...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT