Write a program to allow the following interactive session

Write a program to allow the following interactive session: >> GasPrice Enter year: 2015 Enter month: 9 Enter day: 23 Enter gas price per gallon in dollars: 2.348 Enter amount of gas in gallons: 10 On 9/23/2015 the price of gas was $2.35. Thus, 10 gallon of gas is $23.48. >> Notice the dollar sign (S) and the periods at the end of the displayed sentences. Show two cases (1) the example above, and (2) an example on your own. Submission: 1 m-file and a printout of the command window.

Solution

% matlab code

year = input(\"Enter year: \");
month = input(\"Enter month: \");
day = input(\"Enter day: \");
price = double(input(\"Enter gas price per gallon in dollars: \"));
amount = input(\"Enter amount of gas in gallons: \");

total = amount*price;
fprintf(\"On %d/%d/%d the price of gas was $%0.3f.\ Thus, %d gallons of gas is $%0.3f.\ \",day, month, year, price, amount, total);

%{
output:

Enter year: 2015
Enter month: 9
Enter day: 23
Enter gas price per gallon in dollars: 2.348
Enter amount of gas in gallons: 10
On 23/9/2015 the price of gas was $2.348.
Thus, 10 gallons of gas is $23.480.


Enter year: 2014
Enter month: 6
Enter day: 23
Enter gas price per gallon in dollars: 3.456
Enter amount of gas in gallons: 20
On 23/6/2014 the price of gas was $3.456.
Thus, 20 gallons of gas is $69.120.

%}

 Write a program to allow the following interactive session: >> GasPrice Enter year: 2015 Enter month: 9 Enter day: 23 Enter gas price per gallon in dolla

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site