
Thanks in advance
This post has been edited by RViN: Feb 17 2006, 08:36 PM
Help please, a few questions, C programming
|
|
Feb 15 2006, 09:24 PM, updated 20y ago
Return to original view | Post
#1
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
Any help on this would be appreciated, since I am a complete newb at this
![]() Thanks in advance This post has been edited by RViN: Feb 17 2006, 08:36 PM |
|
|
|
|
|
Feb 15 2006, 10:11 PM
Return to original view | Post
#2
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
I was just looking at some pointers to start it off. I mean I know the basics but I dont know the equations to put in the code to make it work. Like the second one where there and nth posibilities.
hmn.. thanks anyways. |
|
|
Feb 17 2006, 08:34 PM
Return to original view | Post
#3
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
QUOTE(silverhawk @ Feb 16 2006, 01:31 PM) 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. Thanks for the help but I manage to figure quite abit out from the notes I had though inadequate.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. This is what I came up with CODE code removed for easier scrolling I cant get the menu to work although the rest do work on their own though not as they are suppose to but I can sort that later. I need to get themenu to work. Any ideas? This post has been edited by RViN: Feb 19 2006, 08:30 PM |
|
|
Feb 18 2006, 12:28 AM
Return to original view | Post
#4
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
QUOTE(silverhawk @ Feb 17 2006, 08:51 PM) Cheers for the help again. Its working, I removed the goto function.I did a few modificationas as well. Can you please help me and make sure I done it correctly CODE Code removed for easier scrolling Thanks again. I really appreciate the time you are taking to help me out. This post has been edited by RViN: Feb 19 2006, 08:29 PM |
|
|
Feb 18 2006, 02:01 AM
Return to original view | Post
#5
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
QUOTE(silverhawk @ Feb 18 2006, 01:09 AM) I see you are adding the menu code again in each function. That is of course not a smart thing to do... Thanks again. I think thats it for now. Just need to check my formula for the calculations are correct.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 |
|
|
Feb 19 2006, 12:01 PM
Return to original view | Post
#6
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
Ok just discovered one more problem. When the menu appers and a letter besides a number, the screen will keep on going without halting.
I think there must be a way to introduce a character function in it but how do I tie it in with the menu? |
|
|
|
|
|
Feb 19 2006, 08:28 PM
Return to original view | Post
#7
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
I could manage to do it that way because the string function keeps getting "unknown identifier" errors.
I did it this way: CODE #include<stdio.h> void equation(); void calculate_current(); void time_conversion(); void main() { int selection = 0; char input; do { printf("1.Equation Evaluation\n"); printf("2.Current Calculation\n"); printf("3.Time Conversion\n"); printf("4.Quit\n\n"); printf("Enter Selection: "); scanf("%d", &selection); scanf("%c", &input); printf("\n----------------------------------\n\n"); switch(selection) { case 1: equation(); break; case 2: calculate_current(); break; case 3: time_conversion(); break; case 4: break; default: printf("Try Again\n\n"); } } while (selection !=4); } void equation() { int selection = 0; float a, b, c, d, x1, x2, b1, b2; printf("Enter value of A11 :"); scanf("%f", &a); printf("Enter value of A12 :"); scanf("%f", &b); printf("Enter value of B1 :"); scanf("%f", &b1); printf("Enter value of A21 :"); scanf("%f", &c); printf("Enter value of A22 :"); scanf("%f", &d); printf("Enter value of B2 :"); scanf("%f", &b2); printf("\nThe equations are :\n"); printf("%.fX1 + %.fX2 = %.f\n", a, b, b1); printf("%.fX1 + %.fX2 = %.f\n\n", c, d, b2); x1=((b1*d)-(b2*b))/((a*d)-(c*b)); x2=((a*b2)-(b1*c))/((a*d)-(c*b)); printf("X1=%.2f, X2=%.2f\n\n", x1, x2); printf("----------------------------------\n\n"); } void calculate_current() { float resistance, total, gtotal; total=0; printf("Enter value of parallel resistances, Enter 0 to end :\n"); scanf("%f", &resistance); while(resistance !=0) { total +=1/resistance; scanf("%f", &resistance); } gtotal=1/total; printf("\nTotal Resistance = %.2f Ohms\n\n", gtotal); printf("----------------------------------\n\n"); } void time_conversion() { int sec, min, hr; printf("Please enter time in seconds :"); scanf("%d", &sec); hr=sec/3600; min=(sec%3600)/60; sec=(sec%3600)%60; printf("%d hours %d minutes %d seconds\n\n", hr, min, sec); printf("----------------------------------\n\n"); } Is it ok to make it like this?? I just added a new character input called input but didnt specify where its saved or used. This post has been edited by RViN: Feb 19 2006, 08:31 PM |
|
|
Feb 19 2006, 10:18 PM
Return to original view | Post
#8
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
The way I did it, there was no need to enter the character twice and when entered a character it will give out the default case though after doing let say function 1 and then it comes back to the menu, if I enter a character it will reperform the function rather than stating the default case.
I did include the string header file (<string.h>) and the standard library header file (<stdlib.h>) but it still agve me the error. Though after doing it with char input[100]; it worked without errors but it required me to enter the character twice to select a function and even though I entered a character or an integer it stil gave me the "You selected " messesage. |
|
|
Feb 20 2006, 07:02 PM
Return to original view | Post
#9
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
5,827 posts Joined: Jan 2003 From: Selayang, Selangor |
QUOTE(silverhawk @ Feb 19 2006, 10:50 PM) You only need to get the input once. So no need 2 scanf() functions. thanks for your input once again. I got it working from the input you gave above. I didnt do it properly the first time.Then convert the input to an integer and assign that integer to the variable selection. |
| Change to: | 0.0122sec
0.10
6 queries
GZIP Disabled
Time is now: 24th December 2025 - 02:43 AM |