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);
} }

View 5 Replies


ADVERTISEMENT

Visual C++ :: Print Out Table Of Temperatures In Celsius With Equivalent Fahrenheit

Oct 28, 2013

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;

[Code] ....

View 3 Replies View Related

C++ :: Write Unit Convertor For Converting Temperatures Celsius / Kelvin And Fahrenheit

Feb 8, 2014

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.

For example:

Kelvin -----> Celsius ------------------> Farhenheit
(Input) (base of conversion) (desired output unit)

Do you think this type of conversion is okay?

View 1 Replies View Related

C++ :: Temperature In Celsius And Fahrenheit - No Output

Mar 8, 2013

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;

fahrenheit = 0;
celsius = 100;

[Code] ....

View 1 Replies View Related

C/C++ :: Fahrenheit To Celsius And Celsius To Fahrenheit Code?

Mar 16, 2015

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;

[code]....

View 6 Replies View Related

C++ :: Testing Cos - Why Angle Is Not 45 Degrees

Apr 25, 2012

I developed this simple sample program to test cos():

Code:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
const float radiansToDegrees = 180.0f / 3.141592653589793f;
float c = sqrt(2.0f);
float a = 1;
float angleRadians = cos(a/c);
float angle = radiansToDegrees*angleRadians;
}

I expected angle to be 45 exactly, but it's value is: angle = 43.558804

Why is the angle not 45 degrees? What did I do wrong?

View 4 Replies View Related

C++ :: Law Of Cosines Converting To Degrees Error

Feb 17, 2013

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;

[Code].....

View 1 Replies View Related

C++ :: Built In STD Functions For Converting Degrees To Radians?

Nov 30, 2014

Are there STD functions for converting degrees to radians and radians to degrees?

I know I can write my own but in the particular application I would like to use built-in ones for maintainability.

View 9 Replies View Related

C++ :: Creating Script That Can Rotate Image Through Some Number Of Degrees

Dec 3, 2014

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.

<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Final</title>
</head>
<body>
<canvas id = "drawRectangle" width = "200" height = "200"
style = "border: 5px solid black;">
</canvas>

[code]....

View 2 Replies View Related

C++ :: Rotates A Vector 90 Degrees - Values Won't Stay Negative

Jan 21, 2015

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 };
}

View 8 Replies View Related

C :: Fahrenheit And Celsius Converter?

Feb 5, 2013

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)

[Code].....

View 4 Replies View Related

C :: Fahrenheit To Celsius Scale Converter

May 28, 2014

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 ];

[Code] ....

View 7 Replies View Related

C++ :: Program To Convert From Fahrenheit To Celsius - Linking Error?

Jan 6, 2013

So here is the program:

//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".

View 1 Replies View Related

C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

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++)

[Code]...

View 3 Replies View Related

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

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;

[Code]...

View 1 Replies View Related

C++ :: Find The Lowest And Highest Temperatures?

Sep 29, 2013

How can I properly find the lowest and the highest temperatures?

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

[Code]....

View 1 Replies View Related

C :: Calculate Black Body Spectra Over User-entered Range Of Wavelength And Temperatures

Jul 29, 2013

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:

3100 1915076038
3110 -1233496775
3120 1741010116
3130 1229780625
3140 421722788
3150 -1874760945
3160 1654746252
3170 1062468321
3180 -795217626
3190 -1141129750
3200 -1570716956
3210 539385985

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:

Code:

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>

[code]....

View 14 Replies View Related

C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies View Related

C++ :: Displaying Celsius Temperature?

Dec 1, 2014

I am using Microsoft Visual C++ 2010 Express.

This is my Algorithm. [URL] ....

#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...

View 5 Replies View Related

C++ :: While Loop Stops Output

Jun 19, 2014

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.

View 2 Replies View Related

C++ :: Struct Output Using A Loop?

Nov 6, 2013

trying to output my struct to a for loop. I understand how to output the struct but not into a for loop.

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
struct Date {
int day;
int month;
int year;

[code]....

View 16 Replies View Related

C/C++ :: Take Temperature In Fahrenheit And Convert It Into Centigrade

Feb 10, 2015

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;
}

View 4 Replies View Related

C/C++ :: For Loop Not Producing Correct Output

Nov 14, 2014

Something is wrong with option 1. For some reason it adds 1, 2, 3, 4 ... 5 onto the output and I can't think why. Here is a screenshot.

Also how can I make the output a little neater? I tried to use but it just looks horrible.

I had linked the source code! Why is there no edit button?!

#include<iostream>
using namespace std;
int main(){
int option;
cout << "Welcome to my program. Please select a following option.

[Code] .....

View 3 Replies View Related

C++ :: Count Function - Nested Loop Output

Feb 28, 2013

What does the following nested loop output ?

count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}

View 9 Replies View Related

C++ :: Writing Output Of While Loop To Text File?

Jul 30, 2014

[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:

double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};

[Code]....

View 2 Replies View Related

C++ :: Displaying Correct Output By Using For Loop (with Pointers)

Feb 4, 2014

I wanted to display the correct output by using a for loop at the end of my code, but for some reason it's not working correctly.

#include <iostream>
using namespace std;
int main() {
int* ipArray[3];
for(int i = 0; i < 3; i++) {
ipArray[i] = new int [5];

[Code] .....

What I wanted to do is pretty much match my 1st out put like 0 1 2 3 4 but my 2nd output only outputs 24's and I don't know why

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved