C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2008, 05:44 AM   #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..
patron is offline   Reply With Quote
Old 03-16-2008, 05:50 AM   #2
C++ Witch
 
laserlight's Avatar
 
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   Reply With Quote
Old 03-16-2008, 06:11 AM   #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..
patron is offline   Reply With Quote
Old 03-16-2008, 06:24 AM   #4
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
what is parse line arguments??
I am talking about command line arguments.

Quote:
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-16-2008, 06:36 AM   #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   Reply With Quote
Old 03-16-2008, 06:42 AM   #6
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
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.

Quote:
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-16-2008, 06:47 AM   #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   Reply With Quote
Old 03-16-2008, 06:56 AM   #8
C++ Witch
 
laserlight's Avatar
 
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   Reply With Quote
Old 03-16-2008, 07:03 AM   #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   Reply With Quote
Old 03-16-2008, 07:05 AM   #10
C++ Witch
 
laserlight's Avatar
 
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   Reply With Quote
Old 03-16-2008, 07:12 AM   #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   Reply With Quote
Old 03-16-2008, 07:18 AM   #12
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
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.

Quote:
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("%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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-16-2008, 07:24 AM   #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   Reply With Quote
Old 03-16-2008, 07:30 AM   #14
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 12,459
Quote:
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
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 03-16-2008, 07:36 AM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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