how to print and save?

This is a discussion on how to print and save? within the C Programming forums, part of the General Programming Boards category; I suggest that you post your current code. Indent it more consistently, please....

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    I suggest that you post your current code. Indent it more consistently, please.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    here's my current code..


    Code:
    #include<stdio.h>
    float enter_hours(float w);
    float calculateCharges(float x,float y);
    
    int main ()
    
    {
    
     for (int count=1;count<=3;count++);
     {
    	float a;
    	float p;
    	float q;
    
    	printf("Car\tHours\tCharges\n");
    	printf("%d\t%.1f\t%.2f",count,enter_hours(a),calculateCharges(p,q));
    	count++;
     }
    return (0);
    }
    
    float enter_hours(float w)
    {
      scanf("%f",&w);
      return w;
    }
    
    float calculateCharges(float n,float x)
    {
      if (x<=3){
      return 2.00;
      }
    
      if (x>3 && x<24){
      n=x-3;
      return 2.00+0.50*n;
      }
    
      if (x==24){
      return 10.00;
      }
     return x;
    }

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    You should use variable names that are more descriptive.

    The main problem at this point is that you are reading in the input while calculating and printing the output. You probably should be reading the input into an array, then do the calculation and output using the array.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    i'm so so so sorry..

    but i really don't understand..

    the things that you have kindly explained to me seems so hard for me to interpret...

    i can hardly understand what you are talking..

    i'm so sorry..

    could you explain or show me what should i do to undo these warnings...?

    "possible use of 'p' before definition in main ()"

    thanks..

  5. #20
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    float enter_hours(float w)
    {
      scanf("&#37;f",&w);
      return w;
    }
    Why do you pass w as a parameter? Do you use its value? No.
    so it should be like that:
    Code:
    float enter_hours(void)
    {
      float w;
      scanf("%f",&w);
      return w;
    }
    Code:
    float calculateCharges(float n,float x)
    What is n and what is x?

    Shouldn't be only one input - number of hours spent on the parking?
    Where do you initialize this value before calling your function?

    What should be the output for 23.5 hours parking?

    How do you transfer value returned by enter_hours to the calculateCharges?
    Where do you calculate Total?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #21
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Quote Originally Posted by vart View Post
    Code:
    float enter_hours(float w)
    {
      scanf("&#37;f",&w);
      return w;
    }
    Why do you pass w as a parameter? Do you use its value? No.
    yes.. i did use it.. w supposed to be hours input by user..
    it is used to calculate the charge..

    What is n and what is x?
    i posted the question on other thread titled "assistance in function"...

    please have a look at there and it may kind of explain most of the things you have asked..

    Shouldn't be only one input - number of hours spent on the parking?
    there are 3 cars to be included in the systems..

    What should be the output for 23.5 hours parking?
    2.00 + (23.5-3)*0.50=12.25

    How do you transfer value returned by enter_hours to the calculateCharges?
    Where do you calculate Total?
    i really don't know as i quite new in function..

    i haven't do the part of total because i already encountered problems without doing the total part...

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    laserlight...

    aren't you going to help me out...???

    anyone..

    please generously help out as i'm still very weak in c programming...

    thanks...

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    People have daily lives, ya know. Be patient.
    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.

  9. #24
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    yes.. i did use it.. w supposed to be hours input by user..
    it is used to calculate the charge..
    It is inputted INSIDE this function - why do you make it a parameter?
    please have a look at there and it may kind of explain most of the things you have asked..
    I do not need your explanation. YOU need this explanation to understand YOUR errors

    there are 3 cars to be included in the systems..
    So what number of cars is doing in this formula:
    Code:
    2.00+0.50*n;
    2.00 + (23.5-3)*0.50=12.25
    so for 23h 30 min you will charge 12$ 50 cents and for 24h - 10$? Don't you see some contradiction here?

    i really don't know as i quite new in function..
    In most cases you do something like
    Code:
    float hours = 4.5;
    float charge = calculate(hours);
    
    ....
    
    float calculate(float hours_parked)
    {
       if(hours_parked <= 3.0f) return 2.0f;
       if(...)
    ...
       return 10.0f;
    }
    So you firstly initialize a variable - in your case using
    hours = get_hours();
    call and only then pass it as a parameter to other function
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-09-2008, 07:27 AM
  2. Open Save and Print (Windows Form)
    By MaGaIn in forum C# Programming
    Replies: 1
    Last Post: 02-24-2008, 06:05 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. how to save or print
    By manson015 in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2002, 12:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21