Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have two questions for you people today, the first question has to do with syntax, the other...well, has to do with something kind of annoying hehehe ;)

 

So let's get started, my problem is this:

 


//
// Converts Celsius to Fahrenheit
//

#include <stdio.h>
#include <iostream.h>

int main(int argc, char* argv[])
{
// Ask what the person wants to convert
char conversion;
cout << "What would you like to convert today?" << "\n";
cin >> conversion;

if (conversion == "b") 'THIS IS THE PROBLEM
cout << "You want to convert " << conversion << "\n";
else
cout << "You suck..." << "\n";

// Enter the temperature in Celsius
int celsius;
cout << "Enter the temperature in Celsius: ";
cin >> celsius;

int factor;
factor = 212 - 32;

int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

cout << "Fahrenheit value is: " << fahrenheit << " degrees" << "\n";
return 0;
}
[/Code]

 

 

At the THIS IS THE PROBLEM comment, is the problem

:rolleyes:

 

You see I'm not totally sure how to compare the char [b]conversion[/b] to the string "[b]blah[/b]".

 

--------------------------------

 

My other question would have to deal with a window that pops up ALWAYS when I build the C++ Application, this is what pops up and it always pops up:

"Reality is fake, Dreams are for real"
  • *Experts*
Posted

conversion is a char so you need to use ' instead of ":

if (conversion == 'b')

Also, you dont need to include stdio.h as you dont use anything from there in your code :D.

Also, if you want your program to not stop running after executing all code, so the person can see results you need to add something that will wait for the keyboard input. You could add this:

int y;
std::cin >> y;

Right before return 0;.

You wont need this if you plan on running your program from command line.

  • *Experts*
Posted
That window is perfectly normal. It just means that you've edited your project since the last time you compiled, and it needs to build its info again.
Posted (edited)

Cool, thanks you guys :)

 

---Edit---

 

AAHH!!

 

It says std is not a namespace or class:

 

int y;
std::cin >> y; 

 

:(

 

 

Now things are all weird...

 

For one I'm not able to enter anything for the cin >> celsius

 

And I don't want a single letter, I want the whole string :(

 

This is a picture of it occuring:

Edited by Diablicolic
"Reality is fake, Dreams are for real"
  • *Experts*
Posted

See if putting this under #include statements gives you errors:

using namespace std;

std is a namespace that contains all the standard functions.

Posted

It says that a namespace with this name does not exist :(

 

here's my stuff, but I still can't figure this out:

 

// 
// Converts Celsius to Fahrenheit
//

#include <stdio.h>
#include <iostream.h>
using namespace std;

int main(int argc, char* argv[])
{
// Ask what the person wants to convert
char conversion;
cout << "What would you like to convert today?" << "\n";
cin >> conversion;

	if (conversion == 'b')
		cout << "You want to convert " << conversion << "\n";
	else
		cout << "You suck..." << "\n";

// Enter the temperature in Celsius
int celsius;
cout << "Enter the temperature in Celsius: ";
cin >> celsius;
cout << "\n";

int factor;
factor = 212 - 32;

int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

cout << "Fahrenheit value is: " << fahrenheit << " degrees" << "\n";

return 0;
}

"Reality is fake, Dreams are for real"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...