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 C# program using repl.it that asks the user for three integers and prints the...
Write a C# program using repl.it that asks the user for three integers and prints the average value as a double. Example calculation (3 + 6 + 7) / 3 = 5.33333333333333 Given the data above, the output should be similar to: The average for the values entered is: 5.33333333333333 As always comments in your code are expected (what why how etc… ) Submit your repl.it link to the assignment dropbox text submission area.
I need this written in C # ASAP Write a C# console program that continually asks...
I need this written in C # ASAP Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
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!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT