Hello mathman54,
Looking at the link that
Albatross posted I can see why you are having problems. I put some comments in the code I found there:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include pch.h // <--- Missing the double quotes.
#include <iostream>
#include math.h // <--- Missing the double quotes. And you should use (cmath).
all of the includes have squiggly lines // <--- Needs to start with // to make it a comment
using namespace std; // <--- Should be avoided, but if you insist find out the hard way.
int main()
{
float temp_f{}, temp_c{};
cout << “Enter temperature in Fahrenheit” << endl; Enter temperature has squiggly lines. // <--- Wrong type of double quotes. A comment should start with //.
cin >> temp_f;
temp_c = (temp_f – 32) * (5.0 / 9.0); // <--- Something may be wrong with the minus sign that you used. I had to delete it and retype it.
cout << “The temperature in Celsius is” << temp_c << :\n”; The temperature has the same problem //< --- Wrong type of double quotes.
// <--- The last part (:\n") should be ('\n'). That may have bee just a typo.
}
| |
#include "pch.h"
. This is created by the VS wizard and not able to be used by everyone. If this is the way that you want to create program solutions that is fine, but leave this line out of your posts to avoid comments about why it should not be there. Also notice that this is in simple double quotes that came from the keyboard. Not the fancy ones that you used which the compiler does not understand.
Line 2 is the correct way to include a header file.
Line 3 should be in <> and you should use "cmath", the C++ version, over "math.h", the C version.
Line 5 should be a comment although I get what you meant it should either start with (//) for a line comment or (/* */) for a block comment. A line comment is considered everything from the 2 forward slashes until you press enter even if it should span 2 or more lines.
In line 11 prefer using "double" over "float". "float" does not store some decimal numbers well and being small than a "double" can really be far off in the number it stores. What is on the left side of the decimal point is not a problem.
In lines 13 and 19 your fancy double quotes may look nice, but the compiler does not understand the value of that character. It is looking for (") or ASCII code 34 decimal or 22 hex. What you are using (“) comes up as ASCII code 147 decimal or 93 hex. A big difference.
Not sure how you came up with using (“) over ("). The angle is small, but make a big difference.
In line 19 at the end you have (:\n") . I think this is just a type and you meant to use ("). Even though the (\n) may appear to be 2 characters it is considered 1 character and single quotes are sufficient for this.
After changing you code it now looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
//#include "pch.h"
#include <iostream>
#include <cmath>
//all of the includes have squiggly lines
//using namespace std; // <--- Should be avoided, but if you insist find out the hard way.
int main()
{
double temp_f{}, temp_c{};
std::cout << "Enter temperature in Fahrenheit: "; //Enter temperature has squiggly lines. <--- Wrong type of double quotes.
std::cin >> temp_f;
temp_c = (temp_f - 32) * (5.0 / 9.0);
std::cout << "\nThe temperature in Celsius is: " << temp_c << '\n'; //The temperature has the same problem <--- Wrong type of double quotes.
return 0; // <--- Not required, but makes a good break point.
}
| |
With the changes I made this code compiles wit no errors or warnings and runs just fine.
With what I just found and read I do not think it is the code you are entering, but the way and what you are using.
Andy
Edit: typos.