Modify the program from Project 4 to compute the area of a triangle. Issue the appropriate prompts for the triangle’s base and height, and change the name of the width variable to base. Use the formula 0.5 × base × height to compute the area. An example of the program input and output is shown below: Enter the base: 5 Enter the height: 7 The area is 17.5 square units.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter2: Problem Solving Using C++using
Section: Chapter Questions
Problem 8PP: (Modify) a. Modify the program you wrote for Exercise 7 to provide the mass of a person as an...
icon
Related questions
Question

Modify the program from Project 4 to compute the area of a triangle.

  1. Issue the appropriate prompts for the triangle’s base and height, and change the name of the width variable to base.
  2. Use the formula 0.5 × base × height to compute the area.

An example of the program input and output is shown below:

Enter the base: 5 Enter the height: 7 The area is 17.5 square units.

Expert Solution
Java Code

import java.util.*;
public class Main
{
 public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
  System.out.print("Enter the base: ");
  double base = scan.nextDouble();
  System.out.print("Enter the height: ");
  double height = scan.nextDouble();
  System.out.println("The area is " + 0.5*base*height +" square units");
 }
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning