danilo of TUP wrote:
Greetings,
im Danilo, a student from TUP Manila and taking up COMPUTER SCIENCE. we
are going to have a defense or we could say a project in turbo c. i
just wanna know how to use the SWITCH FUNCTION cause we really need it
badly.
about the array in the interger type variables, what if i put this:
int num[15];
then print some statements so that the user can put some values
printf("put number/s:");
HOW can i put the number/s in the variable "num"?
scanf("???????? ?????????");
i dont know how what to put in there or should i write puts than scanf?
Your English is not exactly lucid, but I'll do my best.
Firstly, you're asking very basic questions like getting input, filling
an array and so on. It would be better for you to acquire a good book
on C and go through it. If you have trouble with any exercises, then
you can post them here for clarification.
The switch is not a fuction but rather a statement. It general form is:
switch (expression) {
case label: statement1; statement2; ...
case label: statement1; ...
default: statement1; ....
}
The expression 'expression' is evaluated and execution branches to the
case statement that contains a 'label' whose value matches the
evaluated expression. This allows multiple branches from a single
expression.
As for filling an array, typically, you employ a loop like the FOR or
WHILE, containing a prompt, a call to a function like fgets() and then
further checking and conversion of the value.
While for demo programs a simple call to scanf() would be sufficient,
in any worthwhile code, fgets() followed by sscanf() or
strtol()/strtod() etc would be needed. Importantly, you should check
wether each function you've called has succeeded or failed and act
appropriately.
For storing signed integer values you can use:
scanf( "%d", &integer_var );
At this point either work through a hardcopy or online book on C. Then
as questions arise, you can post here.