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; how can i save a value if i don't want to do as follows: printf("Enter the hours parked: "); scanf("%f",&a); ...

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

    how to print and save?

    how can i save a value if i don't want to do as follows:

    printf("Enter the hours parked: ");
    scanf("%f",&a);

    because i don't want the output to have the sentence "Enter the hours parked:"

    the output required is as below(must be exactly the same):
    cars hours charges
    1 1.5 2.00
    2 4.00 2.50
    3 24 10.00
    TOTAL 29.5 14.50

    the charges value are determined by the hours...
    and the user are only required to enter the hours...

    please kindly assist...
    thank you..

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    You can get the user to enter the number of hours parked on the command line, then parse the command line arguments.
    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

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    sorry.. but i don't understand..

    Quote Originally Posted by laserlight View Post
    You can get the user to enter the number of hours parked on the command line, then parse the command line arguments.
    what is parse line arguments??

    the question is suppose to be answered by using function...

    so, is parse the command line arguments meant for functions?

    thanks..

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    what is parse line arguments??
    I am talking about command line arguments.

    the question is suppose to be answered by using function...
    That's secondary to the problem. The problem is how you want the user to enter input.
    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

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    ya..

    yup..

    i agree that it is the secondary to the question i asked..

    and i browse through the link you have attached but i can't understand..

    apparently my lecturer haven't taught me about that topic...

    could you please generously elaborate more on how the user should input the data, please?

    thanks in advance..

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    apparently my lecturer haven't taught me about that topic...
    In that case, your lecturer probably would not want you to use command line arguments. You should either check with your lecturer, or simply do not use it.

    could you please generously elaborate more on how the user should input the data, please?
    You could read the input from a file.

    Of course, you do not actually have to print "Enter the hours parked: ". You could just read the user input and assume that the user knows that it is for hours parked.

    What exactly did your lecturer say, anyway?
    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

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

    actually i posted it..

    the request by my lecturer is as postes in my other thread...

    the title is assistance in function...

    and i included my code in there...

    please help me to have a look at it and i know that my code is terribly wrong as the output is not what i want...

    thanks in advance again...

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Your other thread does not state what the lecturer actually said, only your interpretation of the problem.

    Did your lecturer specify what would be the format of the input?
    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

  9. #9
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    my lecturer just said that the output must be the same as posted...

    no adding.. no reducing...

    the output should only be in this form (no extra sentences):

    car Hours Charge
    1 1.5 2.00
    2 4.00 2.50
    3 24.0 10.00
    TOTAL

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    I see. Then just assume that the user knows what to input, and read input accordingly. Pretend that you printed "Enter the hours parked: ", but do not actually print it.
    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

  11. #11
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    my lecturer just said that the output must be the same as posted...

    no adding.. no reducing...

    the output should only be in this form (no extra sentences):

    car Hours Charge
    1 1.5 2.00
    2 4.00 2.50
    3 24.0 10.00
    TOTAL 29.5 14.50

    i'm finding trouble how to obtain the value for hour since i can't printf and ask the user to input it there..

    please help..
    thank you very much..

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    my lecturer just said that the output must be the same as posted...
    Precisely. If you do not print anything extra, the output will be the same as required.

    i'm finding trouble how to obtain the value for hour since i can't printf and ask the user to input it there..
    Do not printf() anything other than the required output. Just start reading immediately. The user is assumed to know what to input.

    This is an example:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int x;
        scanf("&#37;d", &x);
        printf("You entered %d\n", x);
        return 0;
    }
    Sure, it looks strange, but perhaps your lecturer will do I/O re-direction (if you do not know what that is, just ignore it for now).
    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

  13. #13
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    but i still encounter problem(s)...

    are my code in the previous thread wrong?

    ya.. i know it is wrong..

    but i can't figure out where's those wrong that makes the output not what i want...

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    are my code in the previous thread wrong?
    Yes. Don't you get warnings when compiling? Fix those warnings.
    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

  15. #15
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    but i really don't understand the warning:

    possible use of 'p' before definition in function main ()..

    no matter how i put it there's still warnings around..

    is that warning mean that i should initialize it first inside the main..??

    but i already did that...

    yet it is wrong..

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

Similar Threads

  1. Replies: 2
    Last Post: 05-09-2008, 08:27 AM
  2. Open Save and Print (Windows Form)
    By MaGaIn in forum C# Programming
    Replies: 1
    Last Post: 02-24-2008, 07: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, 04:00 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  5. how to save or print
    By manson015 in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2002, 01:18 PM

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