Thread: how to print and save?

  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
    28,413
    You can get the user to enter the number of hours parked on the command line, then parse the command line arguments.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    are my code in the previous thread wrong?
    Yes. Don't you get warnings when compiling? Fix those warnings.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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..

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, 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, 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, 01:18 PM