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


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/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 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 :: 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++ :: 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++ :: 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++ :: How To Write Boost Unit Test In Visual Studio 2010

Apr 16, 2014

I'm new to c++ and boost library also. I need to test a function of my library. For example

// Functions.hpp
int add(const int x, const int y);
//Functions.cpp
int add(const int x, const int y)
{
return (x + y);
}

Now i need to test add function using boost. I need the result or output in below style. What all settings do i need to do in VS 2010 and how i should include boost test in the project.

==== Run unit tests ====
Running 2 test cases...
./mytest.cpp(13): error in "SimpleTestInMainTestingModule": check 1 == 2 failed
Test suite "Master Test Suite" failed with:
1 assertion out of 2 passed
1 assertion out of 2 failed
1 test case out of 2 passed
1 test case out of 2 failed

View 1 Replies View Related

C++ :: Binary To Decimal Convertor?

May 17, 2014

#include<iostream>
#include<conio.h>
using namespace std;
void main() {
int num1,num2,ans,rem;

[Code] .....

View 6 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++ :: 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/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 :: Assigning A Structure As A Unit

Feb 21, 2014

I am reading the book C Programming Language. On Structures, it says:

"The only legal operations on a structure are copying it or assigning to it as a unit, taking its address with &, and accessing its members."

What does it mean assigning a structure as a unit?

View 12 Replies View Related

C++ :: Install CPP Unit In Solaris?

Apr 3, 2013

How to Install CPPUnit in Solaris? I don't have gcc in Solaris and all the packages I have downloaded for CPPUnit needs gcc to be compiled.

View 4 Replies View Related

C/C++ :: Time Unit Returned From GetProcessTimes

Jan 25, 2014

I have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?

View 3 Replies View Related

C/C++ :: Winsock Sending X264 Nal Unit

Mar 13, 2015

I am currently trying to send a x264 nal unit using WINSOCK with a reliable multicast socket. It isn't decoding properly, and my initial thought is I am not receiving all the bytes correctly. I was hoping some fresh eyes can provide insight on errors or any improvements. I have seen some topics about this subject, and they showed sending entire structs with the socket. However, I am concerned about endianess so I am trying to stay away from that approach. I have commented out the decoding part, until I am confident that I am receiving the nal unit properly.

Server:

#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"

View 4 Replies View Related

C# :: Unit Of Work And Repository Pattern

Oct 18, 2014

I have implemented the IRepository and UnitOfWork Patterns in my project and I have made a little tweak in the UnitOfWork pattern .

public class UnitOfWork : IDisposable {
private DataContext m_Context = new DataContext();
private bool m_disposed = false;

#region Repositories
private GenericRepository<Product> m_ProductRepository = null;
private List<object> m_RepositoryList = new List<object>();
#endregion

[Code] ....

In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.

Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.

View 1 Replies View Related

C++ :: Random Unit Vectors In N-dimensional Space?

Jul 21, 2013

I need a random unit vectors in n-dimensional space. how to build it in C++?

View 6 Replies View Related

C++ :: Running Unit Test On Library - Checking For NAN?

Jan 31, 2012

I am running a unit test on a library and this line keeps failing on Fedora 16, G++ 4.6.2

Code:
assertNAN(double, std::numeric_limits<double>::signaling_NaN()); //sanity check

The assert looks like this

Code:
//needs to copy it so that if its a function call it only does it once
#define assertNAN(type, one) {
type val = (type)one;
std::string lag(#one);
lag += " not a number";

[Code] ...

I am compiling with -DNDEBUG -O3 -ffast-math -fexpensive-optimizations to simulate a production environment. Is there a way to test for NAN consistently?

View 11 Replies View Related

C# :: Breaking Dependency In Static Method For Unit Test?

Feb 6, 2014

I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.

However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.

Function to get history is given as follows:

public static class Auxiliary
{
private static Dictionary<string, MyData> _myData;
public static MyData GetData(string fileName = null)
{
// ...
}
}

I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.

As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.

Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.

View 1 Replies View Related

Visual C++ :: Unit-testing Functions With User-defined Types?

May 4, 2013

How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?

For example

CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);

View 9 Replies View Related

C++ :: Multidimensional Array - Moving Whole Int Array Row As A Single Unit?

Feb 27, 2013

I have a multidimensional array that runs parallel with a string array

Lincoln 120 300 400
Parks 100 500 250
Shakespeare 0 30 50
Ghandi 250 100 40
Ashe 300 50 175
Rodriguez 87 118 320
Curie 284 0 112

I need to sort this and I know how to do it. But I need to sort it again with the highest value in the first row and keep all information in that row paired with the name . So

Lincoln 120 300 400
Parks 100 500 250

Parks 100 500 250
Lincoln 120 300 400

I need so swap this whole rows. I'm using dynamic array. So my question is Do I have to do a bunch of temps to move them? Or is there a way to move the whole int array row as a single unit?

View 3 Replies View Related

C++ :: Converting Int To Char

Feb 20, 2014

Why is this

Code: fFile << (char) (i)p.x, (char) (i)p.y,(char) (i)p.z); not the same as this

Code: printf("%c%c%c", (i)p.x, (i)p.y, (i)p.z);

View 13 Replies View Related

C++ :: Converting Text To Hex

Jan 3, 2013

From my tests I found the problem to be somewhere in the Mantissa part that converts it to binary.

bool xsDLL GetHexFromSF_IEEE754( void* to, Text from, ui08 tSize ) {
from.UpperCase();
int db = 0, dB = 0, dBEnd = tSize, dBLast = ( tSize - 1u ), dbEnd = dBEnd * 8;
ui08 *data = reinterpret_cast< ui08* >( to );
for ( ; dB >= 0; --dB )
data[ dB ] = 0u;

[Code] ....

Adjustments made, still having problems though. After finding a more useful resource [URL] ..... I got the function looking more like it should but am still having problems...

View 1 Replies View Related







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