Write a program that calculates a car's gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold and the number of miles it can be driven on a full tank. It should then display the number of miles than may be driven per gallon of gas.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
Please solve it wothout using boolane and loop, solve it at entry level of programming c++. Thank you
5.
using complete explanations (ex. "The square of 4 is 16", or "The tangent of
45 degrees is 1")
Solve the Programming Challenge 1, "Miles per Gallon", page 146 (144)
Write a program that calculates a car's gas mileage. The program should ask
the user to enter the number of gallons of gas the car can hold and the number
of miles it can be driven on a full tank. It should then display the number of
miles than may be driven per gallon of gas.
Transcribed Image Text:5. using complete explanations (ex. "The square of 4 is 16", or "The tangent of 45 degrees is 1") Solve the Programming Challenge 1, "Miles per Gallon", page 146 (144) Write a program that calculates a car's gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold and the number of miles it can be driven on a full tank. It should then display the number of miles than may be driven per gallon of gas.
144
Chapter 3 Expressions and Interactivity
Program 3-13
1 // This program displays three rows of numbers.
2 #include <iostream>
3 #include <iomanip>
using namespace std;
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
17
18
19
20
21
22
23
24 }
int num1 = 2897,
num4 = 34,
num7 = 390,
// Required for setw
num2 = 5,
num5 = 7,
num8 3456,
// Display the first row of numbers
cout<<setw(6) << num1 <<setw(6)
<< num2 <<setw(6) << num3 << endl;
num3 = 837,
num6 1623,
num9 = 12;
// Display the second row of numbers
cout<<setw(6) << num4 <<setw(6)
Program Output
2897
34
390 3456
<< num5 <<setw(6) << num6 << endl;
5 837
7 1623
12
// Display the third row of numbers
cout<<setw(6) << num7 <<setw(6)
<< num8 <<setw(6) << num9 << endl;
return 0;
By printing each number in a field of 6 positions, they are displayed in perfect columns.
NOTE: A new header file, <iomanip>, is included in Program 3-13. It must be used
in any program that uses setw.
Notice how a setw manipulator is used with each value, because setw only establishes a
field width for the value immediately following it. After that value is printed, cout goes
back to its default method of printing.
You might wonder what will happen if the number is too large to fit in the field, as in the
following statement:
value = 18397;
cout<<setw(2) << value;
In cases like this, cout will print the entire number. setw only specifies the minimum num-
ber of positions in the print field. Any number larger than the minimum will cause cout to
override the setw value.
Transcribed Image Text:144 Chapter 3 Expressions and Interactivity Program 3-13 1 // This program displays three rows of numbers. 2 #include <iostream> 3 #include <iomanip> using namespace std; 4 5 6 7 8 9 10 11 12 13 14 15 16 int main() { 17 18 19 20 21 22 23 24 } int num1 = 2897, num4 = 34, num7 = 390, // Required for setw num2 = 5, num5 = 7, num8 3456, // Display the first row of numbers cout<<setw(6) << num1 <<setw(6) << num2 <<setw(6) << num3 << endl; num3 = 837, num6 1623, num9 = 12; // Display the second row of numbers cout<<setw(6) << num4 <<setw(6) Program Output 2897 34 390 3456 << num5 <<setw(6) << num6 << endl; 5 837 7 1623 12 // Display the third row of numbers cout<<setw(6) << num7 <<setw(6) << num8 <<setw(6) << num9 << endl; return 0; By printing each number in a field of 6 positions, they are displayed in perfect columns. NOTE: A new header file, <iomanip>, is included in Program 3-13. It must be used in any program that uses setw. Notice how a setw manipulator is used with each value, because setw only establishes a field width for the value immediately following it. After that value is printed, cout goes back to its default method of printing. You might wonder what will happen if the number is too large to fit in the field, as in the following statement: value = 18397; cout<<setw(2) << value; In cases like this, cout will print the entire number. setw only specifies the minimum num- ber of positions in the print field. Any number larger than the minimum will cause cout to override the setw value.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY