Using this Java code convert it to C++: public class Program2 {     public static void main(String arg[]) {        //variables to store converted temperature value        double Fahreinheit;        double Celcius;         //Check variable to control while loop        char Check = 'Y';         Scanner input = new Scanner(System.in);         System.out.println("This program converts Temperatures from Fahrenheit to Celsius and vice versa.");         while (Check == 'Y' || Check == 'y') {             //try block to catch the invalid input exception            try {                 //get user input for temperature                System.out.print("Please enter your temperature: ");                double Temperature = input.nextDouble();                 //get user input for the temperature unit designation                System.out.print("Please enter the units (F/C): ");                char Unit = input.next().charAt(0);                 //if unit is Fahrenheit                if (Unit == 'F') {                    //convert to Celsius                    Celcius = (Temperature - 32) * 5 / 9;                    System.out.println("A temperature of " + Temperature + " degrees Fahrenheit is equivalent to " + Celcius + " degrees Celsius.");                } //unit is Celsius                else if (Unit == 'C') {                    //convert to Fahrenheit                    Fahreinheit = ((9 * Temperature) / 5) + 32;                    System.out.println("A temperature of " + Temperature + " degrees Celsius is equivalent to " + Fahreinheit + " degrees Fahrenheit.");                }                 //ask user if they want to continue?                System.out.print("Do you wish another conversion? (Y/N): ");                Check = input.next().charAt(0);                System.out.println();            } //catch block to handle and display the exception message and stop the program            catch (Exception e) {                System.out.println("Invalid Input");                break;            }        }         //when user wishes to discontinue, prints Thank You. Goodbye message to console        if (Check == 'N') {            System.out.println("Thank you. Goodbye.");        }     }}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Using this Java code convert it to C++:

public class Program2 {

    public static void main(String arg[]) {
        //variables to store converted temperature value
        double Fahreinheit;
        double Celcius;

        //Check variable to control while loop
        char Check = 'Y';

        Scanner input = new Scanner(System.in);

        System.out.println("This program converts Temperatures from Fahrenheit to Celsius and vice versa.");

        while (Check == 'Y' || Check == 'y') {

            //try block to catch the invalid input exception
            try {

                //get user input for temperature
                System.out.print("Please enter your temperature: ");
                double Temperature = input.nextDouble();

                //get user input for the temperature unit designation
                System.out.print("Please enter the units (F/C): ");
                char Unit = input.next().charAt(0);

                //if unit is Fahrenheit
                if (Unit == 'F') {
                    //convert to Celsius
                    Celcius = (Temperature - 32) * 5 / 9;
                    System.out.println("A temperature of " + Temperature + " degrees Fahrenheit is equivalent to " + Celcius + " degrees Celsius.");
                } //unit is Celsius
                else if (Unit == 'C') {
                    //convert to Fahrenheit
                    Fahreinheit = ((9 * Temperature) / 5) + 32;
                    System.out.println("A temperature of " + Temperature + " degrees Celsius is equivalent to " + Fahreinheit + " degrees Fahrenheit.");
                }

                //ask user if they want to continue?
                System.out.print("Do you wish another conversion? (Y/N): ");
                Check = input.next().charAt(0);
                System.out.println();
            } //catch block to handle and display the exception message and stop the program
            catch (Exception e) {
                System.out.println("Invalid Input");
                break;
            }
        }

        //when user wishes to discontinue, prints Thank You. Goodbye message to console
        if (Check == 'N') {
            System.out.println("Thank you. Goodbye.");
        }

    }
}

Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education