1. Program that asks the user to enter a number of gallons, and then displays the equivalent in cubic feet.

Chapter 2: 

C++ Programming Basics 

Programming Exercise

Problem # 1:

Assuming there are 7.481 gallons in a cubic foot, write a program that asks the user to enter a number of gallons, and then displays the equivalent in cubic feet.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main(){
    int gallons;
    float cubicFeet;
    cout<<"Enter number of gallons :";
    cin>>gallons;
    cubicFeet=7.481*gallons;
    cout<<endl<<"Cubic Feet in "<<gallons<<" gallons : "<<cubicFeet<<endl;
  
    return 0;
}

Code Screenshot:

Coding tutorial, Computer Science, Programming for beginners, Programming Tutorial, Chapter 2, C++ Programming Basics, Exercise Solution, Object Oriented Programming in C++

 Output:

Coding tutorial, Computer Science, Programming for beginners, Programming Tutorial, Chapter 2, C++ Programming Basics, Exercise Solution, Object Oriented Programming in C++

Let me know in the comment section if you have any question.

Previous Post:
Program that inputs two numbers and finds whether both are equal.


Comments