C++ is not right

Pages: 12
 
#include "pch.h" 


This is valid if pre-compiled headers are enabled and being used by VS. With modem VS I never now use pch as this can itself cause problems.

If pre-compiled headers are being used, then #include <iostream> should be part of the pch and not included outside of pch.h.

What's in pch.h?
You guys are going in the wrong direction with the 32 bit and 64 bit. I was referring to the compiler. In C++ you can compile in x86 and x64. Does it matter whether I use x86 or x 64?
mbozzi, I don't see any spelling errors in the code I put here.
Right now I am getting problems with line 15 and 17.

Severity Code Description Project File Line Suppression State
Error C2371 'temp_c': redefinition; different basic types prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 15

Severity Code Description Project File Line Suppression State
Error (active) E0065 expected a ';' prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17

Severity Code Description Project File LSeverity Code Description Project File Line Suppression State
Error C2065 '”': undeclared identifier prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17 ine Suppression State
Error C3873 '0x201c': this character is not allowed as a first character of an identifier prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17

Severity Code Description Project File Line Suppression State
Error C2065 '“The': undeclared identifier prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17

Please post your code again using code tags. We have no idea what lines 15 and 17 contain.
You guys are going in the wrong direction with the 32 bit and 64 bit. I was referring to the compiler. In C++ you can compile in x86 and x64. Does it matter whether I use x86 or x 64?

No, it doesn't matter. We're not going in the "wrong direction" - instead, focus on producing some C++ code which obeys the language rules. We can address any further issues later on.

mbozzi, I don't see any spelling errors in the code I put here.

I used the term spelling errors to mean syntax errors. Then, I enumerated every such error in your program and gave you a corrected version.

I can't help you if you don't bother to read what I wrote. Help us help you.
Last edited on
//#include "pch.h"
#include <iostream>
#include "math.h"
using namespace std;
int main()
{
9. float temp_f{}, temp_c{};

11. cout << " Enter temperature in Fahrenheit " << endl;

13 cin >> temp_f;

15 temp_c = (temp_f - 32) * (5.0 / 9.0);

17 cout << “The temperature in Celsius is ” << temp_c << "\n" ;
}

A couple of the errors:

Severity Code Description Project File Line Suppression State
Error (active) E0020 identifier "“The" is undefined prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17

Severity Code Description Project File Line Suppression State
Warning C4244 '=': conversion from 'double' to 'float', possible loss of data prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 15


Severity Code Description Project File Line Suppression State
Error C3873 '0x201c': this character is not allowed as a first character of an identifier prog. 12 C:\VS Projects\prog. 12\prog. 12.cpp 17

I hope this helps.

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <cmath>

int main()
{
    double temp_f{0}, temp_c{0};
    
    std::cout << "Enter temperature in Fahrenheit: ";
    std::cin >> temp_f;
    
    temp_c = (temp_f - 32) * (5.0 / 9.0);
    
    std::cout << "  The temperature in Celsius is: " << temp_c << '\n' ;
    
    return 0;
}



Enter temperature in Fahrenheit: 212
  The temperature in Celsius is: 100
Program ended with exit code: 0
againtry
What?
Disregard anything againtry says. They're the resident idiot.
cout << " Enter temperature in Fahrenheit "
cout << “The temperature in Celsius is ”

@mathman54, can you really not distinguish between those types of quotation marks?

Stop using a wordprocessor to create code and start using a text editor.
Read @mbozzi's post further up the thread.

mbozzi I don't get the difference between a - -?
lastchance
It would be better if you told me where on my keyboard the two different quotes are. I only know of the one near the return key.
You guys are spewing stuff here and being aggravating. I don't have the things on my keyboard that you have. I don't know where they are. But you write like I know these things. I am writing the code in VS, not a word processor.
I came here looking for help. This is the beginner forum. So dump the attitude.
Last edited on
its not on the keyboard.
software (ms word, internet browsers, others) can inject unicode ugly quote symbols that are not what c++ accepts as quotes. The only quote you need is the " which is next to enter on normal english speaker keyboards. If that is what you are using and its compiling for you on your system, it may have just gotten adjusted in your browser or something. It happens.

its in the code you posted:

“The temperature in Celsius is ” << temp
vs
"The temperature in Celsius is " << temp

see the difference, side by side, visually? see that left and right are different symbols?
Last edited on
@mathman

Go back to your code in Visual Studio.

Wherever there is a double quote (") go back over it and type it in again from the only double quote that you have on your keyboard.

At the moment you have two distinct types of double quote in your code, so you clearly didn't type them in from the same software package using the same keyboard. Perhaps you tried cutting and pasting some lines of code from a book; who knows?

Nobody here is "spewing stuff" or "being aggravating" or using "attitude". Actually, there seems to be a remarkable degree of patience!
OK I'll use the same quotes I used before. I redid the quotes and it worked! Now does this mean that I have to do this every time I write a program in Visual Studio?
Last edited on
Oh Yeah. I think I said that I have Visual Studio Pro. How do I make exe files?
Under normal circumstances, no, you shouldn't need to think about it. Those Unicode quote characters probably came from copying the text from another application; they were not the result of typing in visual studio.

> How do I make exe files
If your code successfully built and ran, then visual studio already made the exe
Last edited on
Compiling your first program - https://www.learncpp.com/cpp-tutorial/writing-your-first-program/

A few common C++ problems - https://www.learncpp.com/cpp-tutorial/a-few-common-cpp-problems/

I'd suggest you read ALL of "Chapter 0" at Learn C++, many of your recurring questions might be answered already.

FYI, having the Pro version for Visual Studio doesn't make a bit of difference for you, someone learning C++, to create apps.
Topic archived. No new replies allowed.
Pages: 12