Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Celsius to Fahrenheight converter error

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Fri Jul 10, 2009 5:25 pm    Post subject: Celsius to Fahrenheight converter error Reply with quote

Code:
//Celsius to Fahrenheit July 10, 2009

#include <iostream>
using namespace std;

int Celsius;
int Fahrenheight(int);

int main()
{
   cout << "Please enter a Celsius value: ";
      cin >> Celsius;
      int degree = Fahrenheight(degree);
      cout << Celsius << " degrees Celsius is " << degree << " degrees Fahrenheit";
      cin.get();
      cin.get();
      return 0;
      
}
int Fahrenheight(int degree)
{
   return degree =  1.8 * Celsius + 32;
}


I get this error after I type an integer into
Code:
cin >> Celsius;


Run-Time Check Failure #3 - The variable 'degree' is being used without being initialized.

It gives me the option to hit Continue, or Break, and when I hit Continue the code continues on and the program gives me a Fahrenheight value. I dunno why I am getting this error. I am using VC++.

_________________
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Fri Jul 10, 2009 5:42 pm    Post subject: Reply with quote

Change
Code:
int degree = Fahrenheight(degree);
to
Code:
int degree = Fahrenheight(Celsius);
Back to top
View user's profile Send private message
AndrewMan
Grandmaster Cheater Supreme
Reputation: 0

Joined: 01 Aug 2007
Posts: 1257

PostPosted: Fri Jul 10, 2009 5:45 pm    Post subject: Reply with quote

HolyBlah wrote:
Change
Code:
int degree = Fahrenheight(degree);
to
Code:
int degree = Fahrenheight(Celsius);


Ah, thanks dude Very Happy

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Jul 10, 2009 10:39 pm    Post subject: Reply with quote

It will actually work fine like that, despite the error, because the "Fahrenheight" function doesn't even use it's argument.

Code:
int Fahrenheight(int degree)
{
   return degree =  1.8 * Celsius + 32; //degree is nowhere to be found
}


Code:
int degree = Fahrenheight(0);
for example will also get rid of the warning and work fine.


Even more fun is the type conversion warning your code will throw.
Quote:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data


1.8 is going to be considered a double.
1.8f is going to be seen as a float.

You're trying to return an int though, so the compiler will likely just convert it on it's own, but give you the warning you deserve.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites