943,621 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 1868
  • C RSS
Jun 28th, 2007
0

Help needed

Expand Post »
I am a beginner in computers, i would like to be assisted in writing a simple program that inputs a fraction in the form of a/b and c/d and culculates the sum and returns the answer in the simlest form as in p/q.

Notes
do not allow zero as the denomenator
  1. #include<stdio.h>
  2. int numerator a, denomenator b, , second numerator c, second denomenator d, first new numerator x, second new numerator y, new denomenator bd, sum of first new numerator x and second new numerator y p, simplest form of bd, q, ;
  3.  
  4. main()
  5. {
  6. printf("\nËnter value for the numerator a");
  7. scanf("%d",&a);
  8.  
  9. if(numerator a==3)
  10. {
  11.  
  12. printf("Enter value for denomenator b\n");
  13. scanf("%d",&b);
  14.  
  15. if(denomenator b==4)
  16. {
  17. else
  18. {
  19. If (denomenator is 0)
  20. printf("go to again");
  21.  
  22. printf("\nËnter value for the second numerator c");
  23. scanf("%d",&c);
  24. if(numerator c==5)
  25.  
  26. printf("\nËnter value for the second denomenator d");
  27. scanf("%d",&d);
  28. If (denomenator d==3)
  29. {
  30. else
  31. {
  32.  
  33. If (denomenator is 0)
  34. printf("go to again");
  35.  
  36. a/b + c/d
  37.  
  38. bd= b*d
  39.  
  40. x== bd/b*a
  41.  
  42. y== bd/d*c
  43.  
  44. p== x+y
  45.  
  46. if (p>= bd)
  47.  
  48. printf("The whole number is %d, p/bd);
  49. printf("The remainder is %d, p%bd);
  50. }
  51.  
  52. else
  53. {
  54.  
  55. if (p%ab==q)
  56. printf("The remainder is %d, p%q)
  57. }
  58.  
  59. else
  60. {
  61.  
  62. printf("The total sum is %d, p/q);
  63. }
  64. return [o]
Lookin forward to your prompt and positive response.
thanks
Last edited by WaltP; Jun 28th, 2007 at 11:58 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bobs360 is offline Offline
8 posts
since Jun 2007
Jun 28th, 2007
0

Re: Help needed

Click to Expand / Collapse  Quote originally posted by bobs360 ...
I am a beginner in computers, i would like to be assisted in writing a simple program that inputs a fraction in the form of a/b and c/d and culculates the sum and returns the answer in the simlest form as in p/q.

...

Lookin forward to your prompt and positive response.
thanks
Sure. But you didn't mention what help you need? Is there something wrong with your code?

Also, please read this and this. They will help you get the best help possible.
Moderator
Reputation Points: 3278
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,717 posts
since May 2006
Jun 28th, 2007
0

Re: Help needed

Looking at your code, I can clearly see that you are desperately struggling with the language. Maybe you should try to get a firm grip over the langauge(or computer science concepts) rather than diving into problems straight away.

This link has some good resources for beginner C programmers.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jun 29th, 2007
0

Re: Help needed

Thanks for your prompt reply. Could you please humbly take me through the problem, thanks!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bobs360 is offline Offline
8 posts
since Jun 2007
Jun 29th, 2007
0

Re: Help needed

Namaste,

Let me outline the problems am having in writing my C program

1. How can one declare two fractions, say a/b and c/d, further as i work through the problem i find myself declaring so many variables, is that normal?
2. Still on declarations, is it ok for one to use a lot of verbatim in doing the same (read declare) trying to explain each and every variable, just having a look at the mess i've done? If its not ok, how should I go about it sighting a simple example?
3. I also have a problem in the last part of the program, giving the the answer in the simplest/reduced form.

Please help me to directly solve this problem at the same time make me learn how to solve future problems,
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bobs360 is offline Offline
8 posts
since Jun 2007
Jun 30th, 2007
1

Re: Help needed

You can't have whitespace in a variable's name like this:
int numerator a;

You'd have to declare that variable something like this instead:
  1. int numerator_a;
Then if you wanted to store an integer in this variable using scanf,
it would be this:
  1. scanf("%d", &numerator_a);
Notice how the text after the ampersand (&) needs to be the same as how its declared.

It's probably best to go back and get shorter programs working first, before a longer program like this.
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Jun 30th, 2007
0

Re: Help needed

Bobs, I would still recommend you to read some good tutorials on C or get some good C books from a store near you to do some reading. Without putting effort or learning on your part, explaining what is wrong and what is right would be too difficult for us.

Please start reading this.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Jul 3rd, 2007
0

Re: Help needed

Thanks I will
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bobs360 is offline Offline
8 posts
since Jun 2007
Jul 3rd, 2007
0

Re: Help needed

Hi,

Thanks for your reply, what else did you notice wrong?. Please inform me. :-)

Regards,

Bobs
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bobs360 is offline Offline
8 posts
since Jun 2007
Jul 3rd, 2007
0

Re: Help needed

I only noticed that you have just started out with programming. Read good tutorials, practice a lot and come back when you have got specific queries. :-)
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: linker and linkage in c
Next Thread in C Forum Timeline: Float/Double to String conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC