Beginner Questions

Diablicolic

Well-known member
Joined
Jul 28, 2003
Messages
168
Location
Your Neighbor
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 lets get started, my problem is this:

Code:
// 
// 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;
}


At the THIS IS THE PROBLEM comment, is the problem
:rolleyes:

You see Im not totally sure how to compare the char conversion to the string "blah".

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

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:
 

Attachments

conversion is a char so you need to use instead of ":
Code:
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:
Code:
int y;
std::cin >> y;
Right before return 0;.
You wont need this if you plan on running your program from command line.
 
That window is perfectly normal. It just means that youve edited your project since the last time you compiled, and it needs to build its info again.
 
Cool, thanks you guys :)

---Edit---

AAHH!!

It says std is not a namespace or class:

Code:
int y;
std::cin >> y;

:(


Now things are all weird...

For one Im not able to enter anything for the cin >> celsius

And I dont want a single letter, I want the whole string :(

This is a picture of it occuring:
 
Last edited by a moderator:
See if putting this under #include statements gives you errors:
Code:
using namespace std;
std is a namespace that contains all the standard functions.
 
It says that a namespace with this name does not exist :(

heres my stuff, but I still cant figure this out:

Code:
// 
// 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;
}
 
Back
Top