Thread: Need Help

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    30

    Need Help

    Hey Guys I need help.....I am new to programming and I am taking a C class. I use Dev C++ as my compiler. This is my code but when i run it Dos wont stay up....can you guys give me some info to keep dos open??? Thanks Clezzie

    Code:
    // This Program will convert Kelvin to degrees Rankin
    
    #include <math.h>
    #include <stdio.h>
    
    int main()
    {
    	/* Declare Vairables*/
    	int rankin = (9/5);
    	float kelvin = rankin - 459.67;
    	
    	// print degrees in farenhiet
    	printf("Kelvin converted in to degrees is %4.2f\n",kelvin);
    	return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Edit to note: You've got a lot of surprises waiting in your code, too, so we'll be expecting to here more.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    Quote Originally Posted by tabstop View Post
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Edit to note: You've got a lot of surprises waiting in your code, too, so we'll be expecting to here more.
    Thanks...how would i run it from command though???

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by clezzie View Post
    Thanks...how would i run it from command though???
    Open a command prompt window. Navigate to the directory where you put your program. Type the name of the program. (You don't have to type the ".exe" part.)

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by clezzie View Post
    Hey Guys I need help.....I am new to programming and I am taking a C class. I use Dev C++ as my compiler. This is my code but when i run it Dos wont stay up....can you guys give me some info to keep dos open??? Thanks Clezzie

    Code:
    // This Program will convert Kelvin to degrees Rankin
    
    #include <math.h>
    #include <stdio.h>
    
    int main()
    {
    	/* Declare Vairables*/
    	int rankin = (9/5);
    	float kelvin = rankin - 459.67;
    	
    	// print degrees in farenhiet
    	printf("Kelvin converted in to degrees is &#37;4.2f\n",kelvin);
    	return 0;
    }
    Do you REALLY think that an int, could somehow be assigned a value of 9/5?



    system ("pause"), will hold a console window open. Not the best programming practice, but good enough for now.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Adak View Post
    Do you REALLY think that an int, could somehow be assigned a value of 9/5?

    You know those computers are magical things, with their own weird arithmetic and everything!

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    Quote Originally Posted by tabstop View Post
    Open a command prompt window. Navigate to the directory where you put your program. Type the name of the program. (You don't have to type the ".exe" part.)
    Ok i am running vista....i am new to programming and i dont know how i would navigate it to that directory...can i get some instructions?? it is in my doucuments in a folder called C Programs

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    Quote Originally Posted by Adak View Post
    Do you REALLY think that an int, could somehow be assigned a value of 9/5?



    system ("pause"), will hold a console window open. Not the best programming practice, but good enough for now.
    LOL i am very new...and a noob to this...but system ("pause")...where would i place this???

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    ok i just put it at the bottom of my code right before return 0.....my compiler is saying 16 C:\Users\Clezzie\C Programs\practice.cpp `system' undeclared (first use this function)

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by clezzie View Post
    ok i just put it at the bottom of my code right before return 0.....my compiler is saying 16 C:\Users\Clezzie\C Programs\practice.cpp `system' undeclared (first use this function)
    To navigate to a directory, you use the "cd" (change directory) command, so you should probably type
    Code:
    cd "C Programs"
    (although the quotes aren't strictly necessary).

    The system() function is defined in the <stdlib.h> header.

  11. #11
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    lol, i had recently a student with whom we did together his "C" projects. When we finished i uploaded them to his academic account in an appropriately named directory. His problem was, that the directory didn't compile as he expected.
    The next lesson was... what is a file system like, and how to use it.
    Maybe we should have a FAQ thread about file systems, and the most common commands?
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can just put getchar() before the return or put a breakpoint at the last line.
    No need to mess around with DOS windows.
    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.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    cpwiki.sf.net/Pause_console

    Code:
    cd "C Programs"
    (although the quotes aren't strictly necessary).
    As far as I know, the last quote isn't necessary, but the first one is. I could be wrong -- it's been a while since I used a Windows console in any capacity.

    Maybe we should have a FAQ thread about file systems, and the most common commands?
    Feel free to start it. cpwiki.sf.net
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by dwks View Post
    cpwiki.sf.net/Pause_console


    As far as I know, the last quote isn't necessary, but the first one is. I could be wrong -- it's been a while since I used a Windows console in any capacity.
    Normally you need quotes, but cd is "special": it knows that the only thing that can follow is a path and nothing but a path, so it doesn't try to split the command line into pieces. It's new-ish.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Hmm. It's also built-in, so I guess that makes sense. I guess I was getting confused because if you type "cd Docu<tab>" to go to Documents and Settings, for example, it tab-completes it with quotes and all.

    I'm guessing it's an XP/Vista/maybe NT thing?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed