### Project not building

I'm a vb.net guy and I'm trying to learn C++. I understand the OO concept very well, and I consider myself a decent programmer. Currently what I'm using is Microsoft Visual C++ 2010 Express and I'm trying to create a console application that will convert Fahrenheit to Celsius:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````#include using namespace std; int main() { cout << "This is a Fahrenheit to Celcius conversion tool. The temperature can be in two different formats: 74 -or- 74.0."; //Loop until the user doesn't want to continue bool looping = true; do { looping = conversion; } while (looping = true); return 0; } bool conversion() { //fahrenheit and celsius variables double fahrenheit; double celsius; cout << "Please type in the Fahrenheit degree:"; //fahrenheit will be what the user entered cin >> fahrenheit; //celsius converted here celsius = f_to_c(fahrenheit); //print out the celsius degree cout << fahrenheit << "degrees = " << celsius << "degrees"; cout << "Continue? y - yes or n - no"; //return true/false based on if the user wants to keep converting if (cin >> "y") { return true; } else { return false; } } double f_to_c(double f) { //celsius = fahrenheit - 32 * 5 / 9, ignoring PEMDAS double c = (f - 32) * 5 / 9; //return the celsius value return c; }``````

However, when building this I get an error:
-edit- it's to big to put in this post, so I'll put it in the next post.

It seems as though I'm doing everything correctly, but I don't know, I'm no C++ expert :P
You need brackets after the word "conversion" on line 13.

You also need to either put the functions before main or forward declare them. I would do the latter.
Last edited on
You need to initialize your functions before main() or define the functions before main.

= is assignment, == is equals
` } while (looping = true);`
I believe I forward declared properly:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include using namespace std; //Forward declare our two functions bool conversion(); double f_to_c(double f); //Main! int main() { cout << "This is a Fahrenheit to Celcius conversion tool. The temperature can be in two different formats: 74 -or- 74.0."; //Loop until the user doesn't want to continue bool looping = true; do { looping = conversion; {}; } while (looping == true); return 0; } bool conversion() { //fahrenheit and celsius variables double fahrenheit; double celsius; cout << "Please type in the Fahrenheit degree:"; //fahrenheit will be what the user entered cin >> fahrenheit; //celsius converted here celsius = f_to_c(fahrenheit); //print out the celsius degree cout << fahrenheit << "degrees = " << celsius << "degrees"; cout << "Continue? y - yes or n - no"; //return true/false based on if the user wants to keep converting if (cin >> "y") { return true; } else { return false; } } double f_to_c(double f) { //celsius = fahrenheit - 32 * 5 / 9, ignoring PEMDAS double c = (f - 32) * 5 / 9; //return the celsius value return c; }``````

I've also added two brackets after conversion as suggested in post #2. Unfortunately it still won't build. This is the error I get:
-Edit- Still to large, I will try to post it on the next post... again.
you can call functions from main. do not define them in main.
The line should be:
 `` `` ``looping = conversion();``

You could actually shorten the whole thing to...
 `` `` ``while( conversion() ){;}``

I feel the general layout is a bit off, though.
I didn't think that I was defining them in main, I thought that declaring the two functions above the Main() was forward declaring. Although I did just google forward declare c++ and that's how it told me to do it.
this is not calling the function, you need paren
` looping = conversion;`

I am assuming here instead of:
` if (cin >> "y")`

you mean:
 ``12345`` `````` char choice; cin >> choice; //return true/false based on if the user wants to keep converting if (choice == 'y')``````

I am not sure why added this:
` {};`
Last edited on
to call a function is like this...

`conversion();`
if looping = what conversion returns, true or false then...

`looping = conversion();`

hold on a moment... I am using same compiler as you so let me copy and paste then I will get back with you.
Now that I made the changes y'all suggested I come up with this:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include using namespace std; //Forward declare our two functions bool conversion(); double f_to_c(double f); //Main! int main() { cout << "This is a Fahrenheit to Celcius conversion tool. The temperature can be in two different formats: 74 -or- 74.0."; //Loop until the user doesn't want to continue while( conversion() ){;} return 0; } bool conversion() { //fahrenheit and celsius variables double fahrenheit; double celsius; cout << "Please type in the Fahrenheit degree:"; //fahrenheit will be what the user entered cin >> fahrenheit; //celsius converted here celsius = f_to_c(fahrenheit); //print out the celsius degree cout << fahrenheit << "degrees = " << celsius << "degrees"; char choice; cin >> choice; //return true/false based on if the user wants to keep converting if (choice == 'y') { return true; } else { return false; } } double f_to_c(double f) { //celsius = fahrenheit - 32 * 5 / 9, ignoring PEMDAS double c = (f - 32) * 5 / 9; //return the celsius value return c; }``````

And it works. My next question is, in the conditional statement where I check if it's y or not, why do I use single quotation marks instead of double? I would assume that with y being a string, it'd be double quotes.
you beat me good job dude. I was just about to paste in the fix!!

anyways..
`choice == 'y'`
because "y" is a character const.
Oh ok, that makes sense. I'm trying to learn C++ by diving into projects, just like I did with vb.net. Starting from small ones like this to full blown data management systems, so it's all a learning process. More than likely I'll start up a new thread :]
but you forgot line 54...

can you spot the error? think int math vs double

although your format might still work... lucky just watch that in future.
Last edited on
Topic archived. No new replies allowed.