C/C++ :: Input 6 Temperatures In Degrees Fahrenheit And Output In Degrees Celsius - For Loop?
Mar 9, 2015
I need to write a program to input 6 temperatures in degrees Fahrenheit and output it in degrees Celsius. I used a for loop but it keeps giving me 0 as the output whenever I enter a temperature...
Code:
#include <stdio.h>
#include <math.h>
int main() {
double farenheit,celsius;
for(int i=0; i<6; i++) {
printf("Enter temperature in degrees farenheit: ");
scanf("%lf",&farenheit);
celsius = (5/9)*(farenheit-32);
printf("Temperature in degrees celsius: %lf
",celsius);
} }
This C++ question is related to Temperatures and Our task is to : Write a well-documented C program that prints out a table of temperatures in Celsius, from 0 to 100, in steps of 5 degrees, with the equivalent Fahrenheit.
To convert temperatures from Celsius to Fahrenheit use the equation : Temp(F) = Temp(C)*9/5 + 32
Include headings on the columns of figures.
Use the following formatting in your printf to produce a tabulated output:
Printf(“%4.1f %4.1f ”, Cent, Fahr);
This format will print each variable in a fieldwidth of 4 digits, with one place of decimal. The ‘ ’ inserts a tab to space the columns. This is our code, but for some reason its not working.
#include<stdio.h> void main() { int Cent=1, Fahr=1; int Temp; int F; int C;
I am trying to write a unit convertor for converting temperatures Celsius, Kelvin and Fahrenheit.
Code: if (select_one == 't' || select_one == 'T'){// this one works perfectly... //This section does not tell you the use of variables. //The use of variables can be seen as comments in the main program
[Code].....
This part of code will be part of a larger Unit Converter program. Do you think this method of conversion is wise? The error codes are for debugging use only.
I convert all temperatures of all units, whether Celsius, Kelvin or Farhenheit into Celsius and then convert it into the units the user wants.
The program should create two integer variables for the temperature in Celsius and Fahrenheit. Initialize the temperature to 100 degrees Celsius. In a loop, decrement the Celsius value and compute the corresponding temperature in Fahrenheit until the values are the same. But for some reason i either get no output or an out put of -43.
#include <iostream> using namespace std; int main() { int celsius; int fahrenheit;
Im trying to write a code that converts Fahrenheit to Celsius and Celsius to Fahrenheit. Im having trouble prompting the user to enter in "f" for Fahrenheit and "c" for Celsius. I am not getting any errors when running the program but the output includes all the cout statements even after I have used :
if (g=='f'|| g=='F') and if (g=='c'|| g=='C')
#include<iostream> using namespace std; int main() { int f_temp; int c_temp; int f,c,g; { cout << "Choose between Fahrenheit and Celsius: " << endl;
I'm trying to find angles A,B,C using law of cosines and I want the answers to be in degrees and the formula to convert the answer to degrees is angle*PI/180. However the answer does not convert to degrees what am I doing wrong?
Code: #include "stdafx.h" #include <iostream> #include <iomanip> #include <cmath> #define PI 3.14 using namespace std;
Create a script that lets you rotate an image through some number of degrees(out of a maximum of 360 degrees). The script should let you specify that you want to spin the image continuously. It should let you adjust the spin speed dynamically.
I have a function that rotates a vector 90 degrees. Only problem is, i never get negative values. For some strange reason, no matter what i do, the value of x is positive. And even if the x is negative. Once i put it into direction (struct with 2 values x and y) it turns again to positive. Im using VSC++2013 ultimate. At first direction was SDL_Point, so i thought it was SDL problem, but now it seems its something else.
if (c == '-') { int x = direction.y; x *= -1; int y = direction.x; direction = { x, y }; }
I know my current program will not compile. How can I store the the start temperature so it can be used again in the final printf statement "start degrees Fahrenheit is converted Celsius."?
Note - I want to use the float data type for precision.
Code:
//THIS PROGRAM WILL CONVERT TEMPERATURES BETWEEN DEGREES FAHRENHEIT AND DEGREES CELSIUS #include <stdio.h> int main(void)
One of the questions requires writing up a code, that converts Fahrenheit scale to Celsius scale.
The relation between temperature in ◦ C and ◦F is given by the formula:
◦C = 5/9 . ( ◦F - 32 )
Write a program that prints a table (just two columns without any borders) with temperature in ◦F and ◦C for temperatures between 0 and 300 ◦F in steps of 20◦. Compile and run your program. I wanted to approach this problem via arrays and for loops, and I wrote up this
Code: #include<stdlib.h> #include<stdio.h> int main() { // begin main() // units double[] celsius = new double[ 16 ]; double[] fahrenheit = new double[ 16 ];
[Code] ....
Now when I'm trying to compile that, the compailer throws an error which makes absolutely no sense to me.
Code: fahrenheitCelsius.c: In function ‘main’: fahrenheitCelsius.c:18:9: error: expected identifier or ‘(’ before ‘[’ token double[] celsius = new double[ 16 ];
//Program to convert from Fahrenheit to Celcius #include <iostream>
double fahrenToCelsius (double t); //precondition: //t is a valid tempreture in Fahrenheit //postcondition: //returns equivalent temp. in Celcius
[Code] .....
And here is the problem: [Linker error] C:UsersOwnerAppDataLocalTempcckex8SZ.o:fahrenToCelsius.cpp: (.text+0x3d): undefined reference to `fahrenToCelsius(double)' collect2: ld returned 1 exit status
I'm suspecting the program maybe that I saved it wrong? I saved it as fahrentoCelsius.cpp inside the folder "Work" ( I created this folder) which is inside the folder "Dev-cpp".
so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; /* Populate the array */ for(nCount = 0; nCount < 5; nCount++)
I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; int nTotal = 0; /* Declare and initialise the value */ float fAverage;
I tried to write a code to calculate black body spectra over an user-entered range of wavelength and temperatures. The equation I'm trying to code is the second one this image (stolen from Wikipedia)The syntax to run it is bbgrid lambda_inic lambda_final temp_inic temp_final inc_T inc_lambda
where bbgrid is the name of the program, lambda_inic and lambda_final are the limits of the wavelenght range (in units of angstroms, 1A=10⁻⁰m), temp_inic and temp_final are the limits of the temperature range (in Kelvins) and inc_T and inc_lambda are the increments. What I want to do is, given the ranges of temperatures and wavelengths, to run the code over the lambdas and the temperatures.
The problem is that the behaviour of the intensities (what I'm calculating) is erratic. Sometimes it is highly positive, sometimes immensely negative and turning between those two. As an example of an output file, I'm getting things like this:
While I was trying to debug the code, I found the problem may reside in the exponential factor in the denominator. I wrote some lines to calculate and print on the screen only the exponential, and it was oscillating like crazy. The output file should produce curves like this:
#include <iostream> #include <iomanip> using namespace std; //function prototypes int getFahrenheit(); double calcCelsius(int tempF)
[Code] ....
for some reason it keeps giving me a Error C2144: syntax error: 'int' should be preceded by ';' on line 16 column 1 Error C2143: syntax error: missing ';' before 'return' on line 34 column 1 IntelliSence: expected a ';' on Line 34 Column 2
I have tried to fix both of these problems and no matter what I do I either get more errors or they wont go away...
As I was testing it, the program suddenly stopped giving an output. Here is the code:
#include <iostream> using namespace std;
int main() { cout << "Ten people ate breakfast with you this morning. Each of them " << "had pancakes. Please enter how many pancakes each of the ten people " << "ate. " << endl;
[Code] ...
The while loop after int glutton does not work and seems to stop the program. I replaced the "glutton" in the cout with "testing testing" and it still did not work. However, when I commented out the loop, it appeared. Finally, it can't be what's inside the loop, because I commented that out too, and it still didn't work.
I am trying to write a program where i take temperature in Fahrenheit and convert it into centigrade. I keep getting this error "The program '[5980] lab3.exe: Native' has exited with code 0 (0x0)."
My Code is :
#include <iostream> using namespace std; int main() { double fahrenheit, centigrade; cout << "Enter the temperature in Fahrenheit: "; cin >> fahrenheit; centigrade = (5/9)(fahrenheit-32); cout << "The Temperature in Centigrade is " << centigrade << endl; return 0; }
[URL] when I try to write my output to a file. I am building a life insurance premium calculator with c++. What my calculator does is read in a text file called "policies.txt" containing a number of different policies. For example:
Pol1 M N 20 100000 1 .04 99 Pol2 F S 30 100000 1 .05 99 Pol3 M S 72 750000 1 .03 99 Pol4 F N 45 1000000 1 .05 99
And using this, it creates a single premium. Once the calculator calculates the premium of each policy, I want it to write out the premium amount of each policy to a textfile called "output.txt". The problem is that when I check my "output.txt" file, only the premium for the last policy shows up. It only reads:
Premium for Pol4 is 220384 When I want it to read:
Premium for Pol1 is 14101.6 Premium for Pol2 is 14221.2 Premium for Pol3 is 582391 Premium for Pol4 is 220384
How come only the last policy is showing up? and is there any way to make all four policies appear in my output text file? Here is my code: