Thread: Try to compile...nothing happens

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    Try to compile...nothing happens

    Code:
    /*******************************************************************************
    * Name: tripAdvanced.c
    * Assignment: LAB 2
    * Date Written: 10/11/2007
    * Course: CS133
    * Purpose: Calculate more usefull info for a car trip
    * Sources:
    *******************************************************************************/
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        printf("Welcome to the Trip Planner!\n"
        "So you are ready to take a trip? Let me help you plan for\n"
        "your fuels costs and required stops to fill up your tank.\n"
        "===========================================================================\n"
        "Please provide answers to the prompts below and I will\n"
        "display a summary for you when I have computed the results.\n"
        "===========================================================================\n"
        "\n");
        
        float MPG, Lcost, Hcost, miles, gallons, LTcost, HTcost;
           
        printf("Please input your car's average miles per gallon >> ");
        scanf("%f", &MPG);
        printf("Please tell me the range of fuel costs you expect to pay (per gallon)."
        "The lowest per gallon cost of fuel is >> ");
        scanf("%f", Lcost);
        printf("The highest per gallon cost of fuel is >> ");
        scanf("%f", Hcost);
        printf("Please tell me how many miles you plan to travel >> ");
        scanf("%f", miles);
        
        gallons= miles / MPG;
        LTcost= gallons * Lcost;
        HTcost= gallons * Hcost;
            
        printf("\n"
        "===============   Trip Summary   =================="
        "\n");
        
        printf("You will need to purchase %.2f gallons of fuel.\n" , gallons);
        printf("The approximate cost of fuel for your trip is between $%.2f and $%.2f.\n" , LTcost, HTcost);
        
    system("pause");
    return 0;
    }
    That is the code I'm trying to compile. The thing is, I know that my compiler (bloodshed) works fine, as I've written several programs though it. But when I try and compile it, the only thing that comes up is "Press any key to continue..."
    I don't get any errors on it either. So then, why wouldn't show IF ANYTHING, my 1st printf?

    Thanks in advanced,
    Kevin

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    23
    I just ran it and got this far but ran into some errors.

    http://i20.tinypic.com/3347xiv.png

    But I know not much about C, but just wanted to say that is how far it went for me so I can't really help out, sorry.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Huh. Just the fact you could get it to run.....

    Mabye I'll uninstall and reinstall bloodshed.

    And I figured there would probably be some errors in it. I still need to add a "would you like to plan another trip (Y/N)" loop in there too.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    23
    Yeah I am using Bloodshed Dev-C++ as well. I know it sounds dumb but make sure you are saving it as a .c For awhile I kept forgetting to save as .c and would save as .cpp on accident. If you can't figure it out might just want to reinstalling. Good luck with your project.

    edit: forgot to say, all I did was copy and paste your code into a new source file and saved it as .c and compiled and run and that is all i did.
    Last edited by nubby; 10-15-2007 at 05:33 PM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Yup, I just made sure it was a .c, and nothing. I'll go reinstall it right now...

    edit: I just uninstalled and reinstalled everything, but it didn't help.....
    Last edited by thor4life; 10-15-2007 at 06:53 PM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Omaha, Nebraska
    Posts
    116
    Quote Originally Posted by thor4life View Post
    Code:
    /*******************************************************************************
    * Name: tripAdvanced.c
    * Assignment: LAB 2
    * Date Written: 10/11/2007
    * Course: CS133
    * Purpose: Calculate more usefull info for a car trip
    * Sources:
    *******************************************************************************/
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        printf("Welcome to the Trip Planner!\n"
        "So you are ready to take a trip? Let me help you plan for\n"
        "your fuels costs and required stops to fill up your tank.\n"
        "===========================================================================\n"
        "Please provide answers to the prompts below and I will\n"
        "display a summary for you when I have computed the results.\n"
        "===========================================================================\n"
        "\n");
        
        float MPG, Lcost, Hcost, miles, gallons, LTcost, HTcost;
           
        printf("Please input your car's average miles per gallon >> ");
        scanf("%f", &MPG);
        printf("Please tell me the range of fuel costs you expect to pay (per gallon)."
        "The lowest per gallon cost of fuel is >> ");
        scanf("%f", Lcost);
        printf("The highest per gallon cost of fuel is >> ");
        scanf("%f", Hcost);
        printf("Please tell me how many miles you plan to travel >> ");
        scanf("%f", miles);
        
        gallons= miles / MPG;
        LTcost= gallons * Lcost;
        HTcost= gallons * Hcost;
            
        printf("\n"
        "===============   Trip Summary   =================="
        "\n");
        
        printf("You will need to purchase %.2f gallons of fuel.\n" , gallons);
        printf("The approximate cost of fuel for your trip is between $%.2f and $%.2f.\n" , LTcost, HTcost);
        
    system("pause");
    return 0;
    }
    i think whats going on is that you're not assigning the variables to pointers and so bloodshed is crapping out.
    its causing a segmentation fault.
    they need their little '&' signs and they should be happy after that.

    hope that works for ya
    ~M.I.

  7. #7
    Gentoo System .......... Doorsdown's Avatar
    Join Date
    May 2007
    Location
    Rhode Island, USA
    Posts
    19
    That is causing the errors, worked fine for me once i made that adjustment
    Last edited by Doorsdown; 10-15-2007 at 09:59 PM.

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Huh. Well, I fixed the errors (thanks btw), but it still only comes up with the "any key to continue.

    I'm gonna go write some super basic "hello world" program and see if it does the same thing....

  9. #9
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Usually, when I see code like that, I immediately think "copy-paste example code from 199x" (first tip off is rampant use of floats).
    Make sure that whatever code you use, you understand what it does and why you're using it, not just because "it makes things work right". I.E., make sure you fully understand what printf and system do.
    Your program is probably running fine (after you correct for the pointers... and while you're at it, you may aswell change the tacky use of floats (floats are so ninteen-ninety-my-computer-only-has-8-megs-of-memory , all the cool people use doubles now for real values) and horrid imperial system while your at it ), its just that system() is probably clearing your terminal or creating a new one in which the only thing you see is the "any key" message.
    If you want to prompt for termination, use getc or, to a less portable (but easier) solution, getch

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Well, I figured out what the issue was. When you start a new project in bloodshed, you have to say that it's a blank project, now a .dll or anything like that. Well....I wasn't clicking that.

    And now to hijack my own thread, onto the topic of making that "Would you like to plan another trip (Y/N)?"

    Would I use a do statement? That's the only thing I can think of doing (keep in mind I'm about 2 weeks into my C class, so I don't know anywhere near all the tools I can use). I just dont know how to word it.

    I was thinking something like assigning Y=1 and N=0. Then when the user imputs Y or N, the program reads that, and goes from there. However, I have NO IDEA how to make that work

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Use One variable like answer
    Put the user input into it - as you already know how

    Check in the loop condition if the answer == 1 - otherwise - exit loop
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 02:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 01:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM