Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Need help bad!

  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile Need help bad!

    DISCLAIMER: I AM NOT ASKING ANYONE TO WRITE MY PROGRAM (just help).

    So, I am new to C programming and I dont understand it very well... My teacher wants me to write a code for the following:

    (Car-Pool Savings Calculator) Research several car-pooling websites. Create an application
    that calculates your daily driving cost, so that you can estimate how much money could be saved by
    car pooling, which also has other advantages such as reducing carbon emissions and reducing traffic
    congestion. The application should input the following information and display the user’s cost per
    day of driving to work:
    a) Total miles driven per day.
    b) Cost per gallon of gasoline.
    c) Average miles per gallon.
    d) Parking fees per day.
    e) Tolls per day.
    total = tolls + parkFee + (miles/mpg)*gasCost
    Output should like this:
    The total miles driven per day: 100
    The cost per gallon of gasoline: $ 3.00
    The average miles per gallon: 19 mph
    The parking fees per day: $ 3.00
    The tolls per day: $4.00
    Your daily cost of driving to work is $ 22.79

    I need help bad, I dont want you to write my code, I want to learn how to do it on my own. If anyone is able to help me complete my assignment that would be awsome. Or give me links, examples, anything to work with to help me understand this language... I am using Microsoft visual c++ 2010 express btw. Thanks everyone in advance for the help.

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This is what I have so far.... I know it might be totally off..

    Code:
    #include <stdio.h>
    
    #include <iostream>
    
    
    
    void main()
    
    {
    	float tolls;
    
    	float parkFee; 
    
    	float miles;
    
    	float mpg; 
    
    	float gasCost
    
    
    
        printf ("The total miles driven per day: ");
    
    	scanf ("%f",&miles); 
    
    
    
    
    	total = tolls + parkFee + (miles/mpg)*gasCost;
    
    	printf("The total miles driven per day: %0.5f \n",radius);
    
    	printf("The cost per gallon of gasoline: %0.5f \n",diameter);
    
    	printf("The average miles per gallon: %0.5f \n",area);
    
    	printf("The parking fees per day: %0.5f \n",circumference);
    
    	printf("The tolls per day: %0.5f \n",circumference);
    
    	printf("Your daily cost of driving to work is: %0.5f \n",circumference);
    
    
    	system("PAUSE");
    
    }
    Last edited by oracleguy; 09-14-2011 at 11:13 PM. Reason: please use code tags when posting

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well start with writing the code to ask the user for those 5 different inputs and storing them in variables. Are you writing this in C or C++? Look in the book that came with your course on reading input from the console.

    Edit: Ok I see your code now, that is a start now you need ask for the remaining four variables and read them in.
    OracleGuy

  • Users who have thanked oracleguy for this post:

    Treymer0 (09-15-2011)

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I am using C, my teacher didnt require a book because he said everything is on the web. Ill start on the inputs.

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ok, so I added this:


    printf ("Total miles driven per day: ");

    printf ("Cost per gallon of gasoline: ");

    printf ("Average miles per gallon: ");

    printf ("Parking fees per day: ");

    printf ("Tolls per day: ");


    scanf ("%f",&miles);

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Ok, now you need to call scanf after the printf to take the user input and store into the correct variable. I see you already declared the variables you'll need except for total. (You'll want to fix that)
    OracleGuy

  • Users who have thanked oracleguy for this post:

    Treymer0 (09-15-2011)

  • #7
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    so printf declares what I want to do, and scanf stores it?

  • #8
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    like this?:


    scanf ("%f",&miles);

    scanf ("%f",&gasoline);

    scanf ("%f",&milespergallon);

    scanf ("%f",&parkingfees);

    scanf ("%f",&tolls);

  • #9
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    printf just prints whatever text you want to the console. That text is what the user reads.

    By declaring I meant declaring variables. When you write float tolls; you are declaring a variable with a name of tolls of type float.

    Your scanfs look correct, put it all together and you almost have it.
    OracleGuy

  • Users who have thanked oracleguy for this post:

    Treymer0 (09-15-2011)

  • #10
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    OK, this is what I have now:


    /* Architect: Tyler Reymer
    Date: 09/14/2011
    Project: Daily cost driving to work.
    */



    #include <stdio.h>

    #include <iostream>



    void main()

    {
    // float

    float miles;

    float gasCost;

    float mpg;

    float parkFees;

    float tolls;

    // Printf in

    printf ("Total miles driven per day: ");

    printf ("Cost per gallon of gasoline: ");

    printf ("Average miles per gallon: ");

    printf ("Parking fees per day: ");

    printf ("Tolls per day: ");

    // Scanf

    scanf ("%f",&miles);

    scanf ("%f",&gasCost);

    scanf ("%f",&mpg);

    scanf ("%f",&parkFees);

    scanf ("%f",&tolls);



    // Calculation


    total = tolls + parkFee + (miles/mpg)*gasCost;


    // printf out

    printf("The total miles driven per day: %0.5f \n",miles);

    printf("The cost per gallon of gasoline: %0.5f \n",gasCost);

    printf("The average miles per gallon: %0.5f \n",mpg);

    printf("The parking fees per day: %0.5f \n",parkFees);

    printf("The tolls per day: %0.5f \n",tolls);

    printf("Your daily cost of driving to work is: %0.5f \n",total);

    // pause screen

    system("PAUSE");

    }

  • #11
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Close but think about this, shouldn't each scanf be right after the question it is accepting input for? Wouldn't that more sense? Fix that and you still need to fix your total variable. I take it you haven't tried compiling it yet?
    OracleGuy

  • Users who have thanked oracleguy for this post:

    Treymer0 (09-15-2011)

  • #12
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ok, so this is what I did... closer? lol im starting to understand this a lot better though.


    // float

    float miles;

    float gasCost;

    float mpg;

    float parkFees;

    float tolls;

    float total;

    // Printf in

    printf ("Total miles driven per day: ")

    scanf ("%f",&miles);

    printf ("Cost per gallon of gasoline: ");

    scanf ("%f",&gasCost);

    printf ("Average miles per gallon: ");

    scanf ("%f",&mpg);

    printf ("Parking fees per day: ");

    scanf ("%f",&parkFees);

    printf ("Tolls per day: ");

    scanf ("%f",&tolls);

    or should i do it more like this for the printf/scanf:

    printf ("Total miles driven per day: ") scanf ("%f",&miles);

  • #13
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ive tried to run it and it says error..

  • #14
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    That is much better. What is the error that you are getting?
    OracleGuy

  • #15
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts
    its just saying there are build errors when i debug it...

    heres the final code (do you see anything wrong?):


    /* Architect: Tyler Reymer
    Date: 09/14/2011
    Project: Daily cost driving to work.
    */



    #include <stdio.h>

    #include <iostream>



    void main()

    {
    // float;


    float miles;


    float gasCost;


    float mpg;


    float parkFees;


    float tolls;


    float total;


    // printf in;


    printf("Total miles driven per day: ");

    scanf("%f",&miles);

    printf("Cost per gallon of gasoline: ");

    scanf("%f",&gasCost);

    printf("Average miles per gallon: ");

    scanf("%f",&mpg);

    printf("Parking fees per day: ");

    scanf("%f",&parkFees);

    printf("Tolls per day: ");

    scanf("%f",&tolls);




    // calculation;


    total = tolls + parkFee + (miles/mpg)*gasCost;


    // printf out;

    printf("The total miles driven per day: %0.5f \n",miles);

    printf("The cost per gallon of gasoline: %0.5f \n",gasCost);

    printf("The average miles per gallon: %0.5f \n",mpg);

    printf("The parking fees per day: %0.5f \n",parkFees);

    printf("The tolls per day: %0.5f \n",tolls);

    printf("Your daily cost of driving to work is: %0.5f \n",total);

    // pause screen;

    system("PAUSE");

    }


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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