Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Help please, a few questions, C programming

views
     
silverhawk
post Feb 15 2006, 09:38 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


We will help you... but first read the following two topics

http://forum.lowyat.net/index.php?showtopic=54524
http://forum.lowyat.net/index.php?showtopic=178516

This is not a homework forum. Show some effort and we will help you figure out what you can't understand.
silverhawk
post Feb 16 2006, 01:31 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


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
post Feb 17 2006, 08:51 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


try using
CODE

int selection = 0;


instead of char.
Also.. why are you using goto statements? ewwww
silverhawk
post Feb 18 2006, 01:09 AM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


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 smile.gif

silverhawk
post Feb 19 2006, 05:20 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


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 smile.gif

silverhawk
post Feb 19 2006, 09:38 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


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
post Feb 19 2006, 10:50 PM

Eyes on Target
Group Icon
Elite
4,956 posts

Joined: Jan 2003


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.

 

Change to:
| Lo-Fi Version
0.0130sec    0.14    6 queries    GZIP Disabled
Time is now: 24th December 2025 - 02:39 AM