![]() |
| | #1 |
| Registered User Join Date: Feb 2008
Posts: 26
| how to print and save? 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.. |
| patron is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| 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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #3 | |
| Registered User Join Date: Feb 2008
Posts: 26
| sorry.. but i don't understand.. Quote:
the question is suppose to be answered by using function... so, is parse the command line arguments meant for functions? thanks.. | |
| patron is offline | |
| | #4 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #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.. |
| patron is offline | |
| | #6 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| Quote:
Quote:
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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #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... |
| patron is offline | |
| | #8 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| 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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #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 |
| patron is offline | |
| | #10 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| 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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #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.. |
| patron is offline | |
| | #12 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| Quote:
Quote:
This is an example: Code: #include <stdio.h>
int main(void)
{
int x;
scanf("%d", &x);
printf("You entered %d\n", x);
return 0;
}
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #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... |
| patron is offline | |
| | #14 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,459
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #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.. |
| patron is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Writing Struct to Binary File as a Save to Disk Operation | Holtzy | C Programming | 2 | 05-09-2008 07:27 AM |
| Open Save and Print (Windows Form) | MaGaIn | C# Programming | 1 | 02-24-2008 07:05 AM |
| Binary Search Trees Part III | Prelude | A Brief History of Cprogramming.com | 16 | 10-02-2004 03:00 PM |
| simulate Grep command in Unix using C | laxmi | C Programming | 6 | 05-10-2002 04:10 PM |
| how to save or print | manson015 | C++ Programming | 2 | 02-11-2002 01:18 PM |