Diablicolic Posted August 17, 2003 Posted August 17, 2003 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: Quote "Reality is fake, Dreams are for real"
*Experts* mutant Posted August 17, 2003 *Experts* Posted August 17, 2003 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. Quote
*Experts* Volte Posted August 17, 2003 *Experts* Posted August 17, 2003 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. Quote
Diablicolic Posted August 18, 2003 Author Posted August 18, 2003 (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 August 18, 2003 by Diablicolic Quote "Reality is fake, Dreams are for real"
Diablicolic Posted August 18, 2003 Author Posted August 18, 2003 I couldn't enter an attachment in an edited post :( Quote "Reality is fake, Dreams are for real"
*Experts* mutant Posted August 18, 2003 *Experts* Posted August 18, 2003 See if putting this under #include statements gives you errors: using namespace std; std is a namespace that contains all the standard functions. Quote
Diablicolic Posted August 18, 2003 Author Posted August 18, 2003 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; } Quote "Reality is fake, Dreams are for real"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.