Outline ·
[ Standard ] ·
Linear+
Help please, a few questions, C programming
|
silverhawk
|
Feb 15 2006, 09:38 PM
|
Eyes on Target
|
We will help you... but first read the following two topics http://forum.lowyat.net/index.php?showtopic=54524http://forum.lowyat.net/index.php?showtopic=178516This is not a homework forum. Show some effort and we will help you figure out what you can't understand.
|
|
|
|
|
|
silverhawk
|
Feb 16 2006, 01:31 PM
|
Eyes on Target
|
Just find out how to write equations in C. Then use your basic math knowledge to find out what equations you will need. Its pretty easy.
The nth possibility is easy too, you just have to know what the limit is. You can do this by asking for the number of pararrel lines first or counting as lines are added to the circuit.
|
|
|
|
|
|
silverhawk
|
Feb 17 2006, 08:51 PM
|
Eyes on Target
|
try using CODE int selection = 0;
instead of char. Also.. why are you using goto statements? ewwww
|
|
|
|
|
|
silverhawk
|
Feb 18 2006, 01:09 AM
|
Eyes on Target
|
I see you are adding the menu code again in each function. That is of course not a smart thing to do... try doing this CODE int selection = 0;
do { /* menu code here */ } while ( selection != 4 );
This way, it will keep going on untill you choose option 4 which is to quit. I will leave the details for you to figure out
|
|
|
|
|
|
silverhawk
|
Feb 19 2006, 05:20 PM
|
Eyes on Target
|
Ahh, this is where you need to do some input validation. One simple method to do is to use a string and then convert it to int. If it fails you output an error message, if it succeeds then u can use it for the menu selection. CODE #include <stdio.h> #include <string.h> /* for the string data type */ #include <stdlib.h> /* for the conversion function */
string input; int selection = 0;
printf("Enter an integer value : "); scanf("%s", &input);
selection = atoi( input );
if ( input == 0 ) { printf("That was not an integer value"); } else { printf("Integer entered was : %d", selection); }
That's an example, wrote it at the top of my head, so there MAY be errors. So fix it yourself
|
|
|
|
|
|
silverhawk
|
Feb 19 2006, 09:38 PM
|
Eyes on Target
|
Did you run your code? if you did, i think you will notice that after you enter a number, you will still have to enter a character. I don't think you want this. Did you include the string header file (<string.h>) and the standard library header file (<stdlib.h>)? I've not touched C in a while, so try declaring the string like this instead.. CODE char input[100]; /* String of 100 characters */
|
|
|
|
|
|
silverhawk
|
Feb 19 2006, 10:50 PM
|
Eyes on Target
|
You only need to get the input once. So no need 2 scanf() functions.
Then convert the input to an integer and assign that integer to the variable selection.
|
|
|
|
|