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
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...
// 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.
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.
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...
C++ Language Problem 2 (Save and Get Info) : Write a program that asks for the...
C++ Language Problem 2 (Save and Get Info) : Write a program that asks for the user's name, phone number, and address. The program then saves all information in a data file (each information in one line) named list.txt. Finally, the program reads the information from the file and displays it on the screen  in the following format: Name: User's Name   Phone Number: User's Phone Number   Address: User's Street Address User's City, State, and Zip Code
Problem 2 (Save and Get Info) : Write a program that asks for the user's name,...
Problem 2 (Save and Get Info) : Write a program that asks for the user's name, phone number, and address. The program then saves all information in a data file (each information in one line) named list.txt. Finally, the program reads the information from the file and displays it on the screen  in the following format: Name: User's Name   Phone Number: User's Phone Number   Address: User's Street Address User's City, State, and Zip Code
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT