Question

In: Computer Science

Assignment 2 is on page 146, question 12. The assignment asks you to write a program...

Assignment 2 is on page 146, question 12. The assignment asks you to write a program to allow a user to enter a temperature in Celsius and convert it to Fahrenheit. Then display the new temperature on the screen. Consider using the fixed, showpoint, and setprecision stream manipulators with your output. (hint, probably points to what sort of numeric variables you should use) The formula to convert from C to F is in the book on page 146.

For extra credit, have your program then ask for the temperature in Fahrenheit and convert to Celsius and display in a similar manner.

Solutions

Expert Solution


#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
float fahrenheit, celsius,fahrenheit_2,celsius_2;

cout << "Enter the temperature in Celsius : ";
cin >> celsius;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout << "The temperature in Celsius : " <<celsius << endl;
cout << "The temperature in Fahrenheit : " <<fixed<<setprecision(2)<< fahrenheit << endl;
  
// for extra credit
cout << "Enter the temperature in Farenheit : ";
cin>>fahrenheit_2;
celsius_2=(fahrenheit_2-32)*5/9;
cout << "The temperature in Fahrenheit : " <<fahrenheit_2 << endl;
cout << "The temperature in Celsius : " <<fixed<<setprecision(2)<< celsius_2 << endl;
return 0;
}


Related Solutions

Programming Assignment No. 5 Write a program that asks the user to enter a positive odd...
Programming Assignment No. 5 Write a program that asks the user to enter a positive odd number less than 20. If the number is 5, 11 or 15, draw a square whose width is the same as the number entered, if 3, 9, or 17, draw a box (a box is a hollowed out square) with the width the same as the number entered, otherwise just present an message saying "To be determined". Write a method for the square that...
For tthat assignment, you are to write a 2 page summary on a Famous Psychologist Erik...
For tthat assignment, you are to write a 2 page summary on a Famous Psychologist Erik Smith Erikson using proper APA (american psychological association) format. Structure of assignment: 1-      Name a.       History of person b.      Context of when they lived c.       DOB/DOD 2-      Contributions to the field 3-      APA format
Write a program call FancyMyName which asks you to write a program that tests the usage...
Write a program call FancyMyName which asks you to write a program that tests the usage of different methods for working with Strings. This program will ask the user to enter their first name and their last name, separated by a space. Read the user's response using Scanner. Separate the input string up into two strings, one containing the first name and one containing the last name. You can accomplish this by using the indexOf() hint*** find the position of...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
// JavaLanguage . You need to write a program that asks the user for an array...
// JavaLanguage . You need to write a program that asks the user for an array size, and then asks the user to enter that many integers. Your program will then print out the sum , average, largest and smallest of the values in the array.
Question : Write a C program that asks the user to enter an integer between 1...
Question : Write a C program that asks the user to enter an integer between 1 and 7 that represents a weekday number (1 = Sunday, 2 = Monday , …… , 6 = Friday , 7 = Saturday) and it prints the day (i.e., Sunday, Monday, …… , Friday or Saturday). The program continuously asks the user to enter a weekday number till the user responds by ‘N’. and give me an output please use printf and scanf #include...
Python question Write a program that asks the user to enter a student's name and 8...
Python question Write a program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT