Need help with code!

This is a discussion on Need help with code! within the C++ Programming forums, part of the General Programming Boards category; Recently I decided to start trying to teach myself C++ and picked up the C++ version of For Dummies to ...

  1. #1
    Registered User skaldicpoet9's Avatar
    Join Date
    Dec 2007
    Posts
    15

    Need help with code!

    Recently I decided to start trying to teach myself C++ and picked up the C++ version of For Dummies to begin at the beginning. However the code that is given in the first chapter doesn't seem to compile when I enter it using C++ Express. The code is as follows:

    Code:
    //
    // Program to convert temperature from Celsius degree
    // units into Fahrenheit degree units:
    // Fahrenheit = Celsius * (212 - 32)/100 + 32
    //
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main(int nNumberofArgs, char* pszArgs[])
    {
    // enter the temperature in Celsius
    int celsius;
    cout << “Enter the temperature in Celsius:”;
    cin >> celsius;
    
    // calculate conversion factor for Celsius
    // to Fahrenheit
    int factor;
    factor = 212 - 32;
    
    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int fahrenheit;
    fahrenheit = factor * celsius/100 + 32;
    
    // output the results (followed by a NewLine)
    cout << “Fahrenheit value is:”;
    cout << fahrenheit << endl;
    
    // wait until user is ready before terminating program
    // to allow the user to see the program results
    system(“PAUSE”);
    return 0;
    }
    And once that is entered in I get a long string of errors at the bottom of the compiler:

    Code:
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2065: '“Enter' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2146: syntax error : missing ';' before identifier 'the'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2065: 'the' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2146: syntax error : missing ';' before identifier 'temperature'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2065: 'temperature' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2146: syntax error : missing ';' before identifier 'in'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2065: 'in' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2146: syntax error : missing ';' before identifier 'Celsius'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(14) : error C2065: '”' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(28) : error C2065: '“Fahrenheit' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(28) : error C2146: syntax error : missing ';' before identifier 'value'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(28) : error C2065: 'value' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(28) : error C2146: syntax error : missing ';' before identifier 'is'
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(28) : error C2065: '”' : undeclared identifier
    1>c:\users\kitty mcevil\documents\visual studio 2008\projects\pro\pro\code.cpp(33) : error C2065: '“PAUSE”' : undeclared identifier
    Is there something that I am entering wrong or did I create the project wrong in C++ Express. (File->New->Project->Win32 Console App->Empty Project)

    Any help would be greatly appreciated, thanks

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Are your quotes all jacked up? They look like Word quotes or something... Fix 'em.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    Yes, the quote characters are wrong.
    You're using ”, but you should be using ".
    There's a difference.

    Also mind your indentation. Visual Studio should take care of that for you, so don't fight it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  4. #4
    Registered User skaldicpoet9's Avatar
    Join Date
    Dec 2007
    Posts
    15
    Thanks, that was the problem

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    At the risk of sounding arrogant. I know it was the problem. Hense the post. What were you using to write your code in the first place? My vote is still MS Word.

  6. #6
    Registered User skaldicpoet9's Avatar
    Join Date
    Dec 2007
    Posts
    15
    I actually have the eBook of C++ for Dummies so I just pasted the code from there into VC++ Express. It was formatted that way in the book I just assumed that it would be fine to use in the compiler. Usually I write my code straight into C++ Express though. So, next time that is what I'll be doing lol...

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    Quote Originally Posted by master5001 View Post
    At the risk of sounding arrogant. I know it was the problem.
    At the risk of sound arrogant, ditto
    I knew it from the start too. Big difference in those characters.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21