C++ :: Temperature Converter From Imperial To Metric - For Loop
Nov 26, 2013
I've been doing some practice programming challenges and I am currently making a temperature converter from Imperial to Metric.
My approach was to make it as simple as possible but it must display correctly and use decent I/O manipulations corresponding with how high the counter is.
This is what I have come up with, and everything seems to work fine for a base where I could possibly add more code to include user input, but before I go to that one step further I'd just like to know if the approaches I have taken to using iomanip is OK practice and I haven't done any serious no-nos, as I haven't seen any code from example videos that people make that includes this!
Here's the code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
[Code] ....
The reason I added the IO manipulators is because I couldn't stand seeing everything not lining up, it looked very sloppy and unprofessional..
View 2 Replies
ADVERTISEMENT
Nov 13, 2014
I'm trying to make a simple temperature converter with a menu that lets users pick which conversion to perform. But, it won't seem to print the right conversion. It just prints the same temperature that I inputted.
for example:
#include <iostream>
using namespace std;
//prints the menu
void userMenu(){
cout << "Temperature Calculator" << endl << endl;
[Code] .....
View 2 Replies
View Related
Jan 16, 2013
I have to write a program for a restaurant and their food has to be cooked on a hot sheet of metal and too cook their burgers properly I must keep a maintain temp of 400 F, for the grill and to measure the temperature using a probe at 12 points, there are 3 elements with 3 points on them
View 2 Replies
View Related
Nov 20, 2014
I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.
To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):
// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;
The two example functions I want to use are defined in that struct ("Data"):
// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}
The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:
// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}
The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);
the error becomes: "expression must have a (pointer-to-)function type."
The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:
// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);
This bit shows no errors by itself. So, my questions:
a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.
b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing
// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object
but that doesn't work ("a pointer to a bound function may only be used to call the function").
View 4 Replies
View Related
Nov 1, 2014
I want to make an application that will check CPU/RAM USAGE and CPU TEMPERATURE and if it meets some requirements it will restart your system or do something else..but my problem is:
1) How do i get that info? (i know that in VB.net there is an easy way) but in C/C++ or Java?
2) Is it possible though a C program to execute a command and parse that info to your program?
I am mainly interested for windows but i need also info for linux too..
View 4 Replies
View Related
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
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
Feb 26, 2013
I'm trying to make a program that takes up to a seven digit binary number and converts it to its decimal equivalent. I'm still a beginner, so this might be a simple question but how do I stop the user from entering anything but 1s and 0s? This means no decimals or numbers other than 1 or 0.I already made it so it won't accept anything below 0 or above 1111111.
View 1 Replies
View Related
Mar 15, 2013
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int N=0, counter=0, counter1=0,counter2=0, temp=0, temp1=0,dec=0,result=0, moder=0;
[Code] .....
This is Binary to Decimal Converter. It's not working. Although Dry Run of this program works fine.
View 4 Replies
View Related
Dec 23, 2013
I am writing a program that converts arabic numbers into roman numerals.
Quote Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number.
Input Validation: Do not accept a number less than 1 or greater than 10.
Prompts And Output Labels. Use the following prompt for input: "Enter a number (1 - 10): ". The output of the program should be of the form "The Roman numeral version of A is R" where A is the Arabic numeral entered (1,2,3,...) and R is the all-capitals form of a Roman numeral, such as VII.
View 14 Replies
View Related
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
Feb 4, 2014
Here is my problem:
Wind Chill = 35.74 + 0.6215T – 35.75(V^0.16) + 0.4275T(V^0.16)
Note: Windchill Temperature is only defined for temperatures at or below 50 degrees F and wind speeds above 3 mph. Bright sunshine may increase the wind chill temperature by 10 to 18 degrees F.
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
double windChillFactor (const double &v, const double &t)
[Code] ....
View 3 Replies
View Related
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
May 23, 2013
I wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
View 7 Replies
View Related
Sep 9, 2014
I was trying to program an decimal to binary converter (8-bits) in C. I am a complete beginner so I tried to put the 1's and 0's of the binary number as they come without reversing the order for beginning. I have seen example on the internet but didn't understand them so I decided to write it as I understood it. So, I typed the code as shown below:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int number;
int BitNum[8], x;
[Code] ....
The problem with the code is that if binary form has 0s in it then program displays a random number instead of a 0. For example if decimal is 7, it should print out 11100000 but it displays only 111(and some stupid numbers instead of 0). I have tried to solve it but failed.
View 7 Replies
View Related
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
Jun 12, 2014
I wrote a program that converts Binary code to Grey code. It works, but I feel like it's highly inefficient. I've also been trying out Project Euler, but I seem to always turn to using vectors whenever solving a problem.
/* Binary to Grey Code Converter */
#include <iostream>
#include <vector>
using namespace std;
// Global Variables (I'd like to not use them because I've been told it's bad practice)
static int numDigits;
int digit;
vector<int> bin;
[Code] .....
View 1 Replies
View Related
Sep 1, 2014
I need to convert a string into a Font object. I'm trying to use the Font Converter but I don't see support for the font Style. I need to save a font to a string and back again using the font name, size and style.
Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");
View 1 Replies
View Related
Apr 8, 2015
I am attempting to reconfigure a working code that before used while loops and if statements to convert a numeric score to a letter grade. I now wish to take this same code however I want to change the char convertGrade(int numScore) to simply use a parallel array as a replacement to the if statements.
The array needs to consist of 3 arrays of fixed size 5:
int minScores[SIZE]
int maxScores[SIZE]
char letterGrade[SIZE]
I know the declarations need to go in the function convertGrade but this is the first time I have worked with arrays and I am having trouble trying to figure out how this array will replace my previous if statement.
In order to access the array elements I need to write specifications such as
minScores[i]
maxScores[i]
letterGrade[i]
(where i = 0, 1, 2, 3, or 4)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int getScore(void);
char convertGrade(int numScore);
[Code] .....
View 5 Replies
View Related
Sep 21, 2014
I recently wrote a program to convert numbers to binary in c++, Well here it is:
#include <iostream>
void recur(int convert) {
if(convert == 0) //if input is 0 , return nothing. {
return;
}
recur(convert/2); // divide convert by 2, get only a 1 or 0
[Code] ....
View 13 Replies
View Related
Apr 18, 2012
Basically I have 2 questions.
1. Because of how limited integers are in terms of storage, the largest binary number i can give seems to be 1 111 111 111. Anything larger breaks the program. Is there any way to increase the largest input I can give without completely rewriting the program? I tried changing the num/numCounter (and the typecasting) to long doubles, but it just messed stuff up (or I did).
2. I'd also like to make it so that if someone inputs a non-binary number my program tells them so and stops. I figured a switch statement within the while loop would work (for when numCounter/divisor is negative or greater than 1), but I was wondering if instead it was possible to use an if statement that could break the while loop?
Anyway, here's the code:
Code:
#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
[code]....
View 7 Replies
View Related
Oct 5, 2014
I'm trying to figure out why the binary to decimal part is not working correctly when the binary value finishes with a 1. In those cases, the decimal value shown in one unit smaller than it should be.
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void Binary_to_Decimal(), Decimal_to_Binary(); //prototype for the 2 functions that contain the converters
int main() //the menu {
int a_Choice;
cout << "Enter 1 - for binary to decimal" << endl;
cout << "Enter 2 - for decimal to binary" << endl;
[code]....
View 2 Replies
View Related
Dec 31, 2014
I am given two month's data (Max, Min, Ave) for every day in that month.
The task is to display all 3 of that data for any selected day in that 2 months.
View 3 Replies
View Related
Jan 20, 2015
What I have to write in "int main" to get 1.room list 2.every room temperature, humidity and heat index 3.and how to increase or decrease every parameter
#include <iostream>
#include <string>
using namespace std;
struct Klinikos //hospital {
string Patalpos; //room
float Temperatura; //temperature
float Dregme; //humidity
bool moreTemp;
float KarscioIndeksas; //heatindex
[Code] .....
View 7 Replies
View Related
Oct 30, 2013
I've been trying to get the numbers for hours now but i can seem to get it right. Here's the problem below:
During the initial period, when the heater is not yet functioning at peak efficiency the heating will increase the temperature inside the building at a rate given by the following equations. During the initial period when the air conditioner is not yet functioning at peak efficacy the air conditioner will decrease the temperature inside the building at a rate given by the same equations.
Interval = (Time since turning on / 2.0 ) - 3.0
Factor multiplying Temperature change per minute = exp( Interval) / ( 1 + exp(Interval) )
These equations can also be used after the heating or air conditioner reaches peak efficiency. These equations converge to 1, so after the heating or air conditioner reach peak efficiency these equations will always give a value of 1.
the value of these equations needs to be multiplied by the RATE TEMPERATURE CHANGES. The RATE TEMPERATURE CHANGES is EITHER the change in temperature inside the building in degrees Celsius per minute caused by heat being extracted by the air conditioning OR the change in temperature inside the building in degrees Celsius per minute caused by the heat being generated by the heating .Temperature change in degrees per minute = Factor multiplying Temperature change per minute * RATE TEMPERATURE CHANGES
Temperature at end of this interval = Temperature at the start of the interval + temperature change due to heat escaping during the this interval + temperature change due to heat generated by the heating system during this interval + temperature change due to heat removed by the cooling system during this interval
i have a:
...rate of -.05 for heat escape w/o cooling or heating
...rate of 0.10 for heat escape w/ cooling
...rate of 0.125 for heat increase w/ heating
...Starting temp=38.00
...Time interval 3.50
I can't seem to find the temp at the ending interval? What i tried doing:
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main () {
double intervals=0.00;
double tempPerMin=0.00;
[Code] ....
The temperature at the end of the interval is suppose to be 37.81 but i can't get the answer. I'm pretty sure this is a logical error from the equations i used but i can't seem to find it.
View 3 Replies
View Related
Dec 1, 2013
I have to create a converter but the results must be in 4 decimal places just like, if i Entered 5000mm the result would be 500.0000cm . what should I do ? I used Float function
View 1 Replies
View Related