Thread: Another Noob Problem

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    Another Noob Problem

    I am trying to learn C++ programming, and am trying to follow along with C++ For Dummies 5th ed. Unfortunately I've encountered a problem with the first project I copied the code exactly like it is in the book, but for some reason the program spits out the same number (-858993460) regardless of what input I give it (supposed to convert temperatures). I am using Microsoft Visual C++ 6.0 to write and compile my code. Any thoughts on this would be greatly appreciated! This is the code I have now:

    Code:
    //
    //    Prograam to convert temperature from Celsius
    //    degree units to Fahrenheit degree units:
    //    Fehrenheit - 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;
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    If this is exactly from the book then the book has a typo (or two).

    These lines don't do anything:
    Code:
    factor - 212 - 32; 
    fahrenheit - factor * celsius/100 + 32;
    Maybe you mean
    Code:
    factor = 212 - 32; 
    fahrenheit = factor * celsius/100 + 32;
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    Yay it works now! Thank you! I hope that this isn't foreshadowing for the rest of the book, I quadruple checked and it has "-" where the "=" should be.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is there a reason you are using such an old compiler?
    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.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    It was given to me and I don't want to shell out the money on a newer one until I know this is something I'm going to stick with.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to shell out money. Latest version (Express edition) is free.
    GCC is a free compiler and Code::Blocks is a popular IDE that works with that compiler.
    You should do yourself a favor and upgrade.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Big problem, but a noob to identify it!
    By lovenetuk in forum C Programming
    Replies: 3
    Last Post: 04-27-2011, 03:30 PM
  2. noob problem in code
    By Dadude in forum C Programming
    Replies: 12
    Last Post: 02-07-2009, 10:28 AM
  3. What is the problem here? (noob question)
    By p_m63 in forum C++ Programming
    Replies: 9
    Last Post: 07-10-2006, 02:50 AM
  4. C++ Problem, I'm such a noob :d
    By Shamino in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2005, 09:52 AM
  5. [noob] i can't even name the problem
    By knoxville in forum C Programming
    Replies: 19
    Last Post: 03-15-2005, 06:32 AM