Beginner Questions

Diablicolic

Centurion
Joined
Jul 28, 2003
Messages
167
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 let's 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 I'm 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 you've 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 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:
 
Last edited:
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 :(

here's my stuff, but I still can't 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