CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013

    Sorry for bad English but i need help

    This C++ question is related to Temperatures and , i was wondering if anyone you will help me on this.

    Our task is to :

    Write a well-documented C program that prints out a table of temperatures in
    Celsius, from 0 to 100, in steps of 5 degrees, with the equivalent Fahrenheit.
    To convert temperatures from Celsius to Fahrenheit use the equation:
    Temp(F) = Temp(C)*9/5 + 32

    Include headings on the columns of figures.

    Use the following formatting in your printf to produce a tabulated output:
    Printf(“%4.1f \t %4.1f\n”, Cent, Fahr);
    This format will print each variable in a fieldwidth of 4 digits, with one place of
    decimal. The ‘\t’ inserts a tab to space the columns.

    This is our code, but for some reason its not working.
    void main()
    int Cent=1, Fahr=1;
    int Temp;
    int F;
    int C;
    for(Cent<=100, Cent++);
    printf("%4.1f \t %4.1f\n", Cent Fahr);
    Temp(F) = Temp(C)*9/5 + 32;

    help please?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Sorry for bad English but i need help

    When doing homework, the first thing to do is to try to become self sufficient, so you don't have to rely on a forum for answering questions. Generally the best way to do this is become familiar with how to debug your program.

    In a nutshell, what debugging allows you to do is to check program flow and inspect variables while the program is running.

    It's often thought to be very difficult by beginners. Fortunately, Visual C++ makes debugging easy.

    In order to debug, you set a breakpoint on a line of code. The breakpoint causes the program to stop execution on the breakpoint, then you can hover the mouse over the program variables to see what's in them. You can also press F11 and F10 to step in and over code. This is useful for stepping into the for loop (for example).

    I see a couple of errors with your code. Namely, the for loop isn't going to do what you expect because you need to get rid of the trailing semicolon and add braces. The printf method doesn't have enough parameters (you're missing a comma in there).

    Heck there are even more errors and this code won't even compile.

    So let me correct my first statement. When you are asked to do a homework assignment, the first thing you need to do is to create a Visual C++ project and paste the code into it and then compile it. Next, resolve the compiler errors so you can get to the point of debugging the program as mentioned earlier.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Sorry for bad English but i need help

    As well as what Arjay stated in post #2, when posting code please use code tags. Go Advanced, select the code and click '#'

    What do you expect the statement

    Temp(F) = Temp(C)*9/5 + 32;
    to accomplish????

    from 0 to 100, in steps of 5 degrees,
    You are told to start at 0, but you initialise Cent to 1?
    Where are you incrementing by 5?

    What is your program design for this assignment? Design first, then code from the design, then fix compile errors, then test/debug.

    You don't seem to have grasped some of the basic concepts of the simple c statements you are trying to use. I suggest you have another look at what your teacher has been discussing because you have made some fundamental mistakes.

    As this is an assignment, we won't write the code for you as that would be cheating.

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.1)

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003

    Re: Sorry for bad English but i need help

    That's not even close to syntactically correct. It's not that it doesn't work, it's that you haven't written a valid C++ program. Start with fixing what the compiler tells you is wrong, and then work on debugging it when you get it running.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)