help!! problems with loops

Reply

Join Date: Mar 2008
Posts: 10
Reputation: barbiegirl is an unknown quantity at this point 
Solved Threads: 0
barbiegirl's Avatar
barbiegirl barbiegirl is offline Offline
Newbie Poster

help!! problems with loops

 
0
  #1
Mar 10th, 2008
hi everyone , i wanted to create a little program with makes the divisions of the elements of a table i wanted to create a loop which will indicate if there's a number in the table then we should c "the division cannot be made", if not we will get the result,the problem is it doesnt work, u may try it n it wont, i know u will say wht is the utility of such stuff, well im just new to C so im tryin with basics,o_O enough talkin here's my source code

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #define n 4
  5.  
  6. void main()
  7. {
  8. //variables
  9.  
  10. double table[n]={0};
  11. long no=1,i;
  12. double x=0,d;
  13.  
  14. //program
  15. for (i=0; i<n; i++)
  16. {
  17. printf("enter the number %d", i);
  18. scanf("%f", &table[i]);
  19. }
  20. printf("gr8\n");
  21. printf("%f", table[0]/table[1]);//this is just to c if it works
  22. for (i=0; i<n; i++)
  23. {
  24. do
  25. {
  26. if(x==0)
  27. no=0;
  28. x=table[i+1];
  29. }
  30. while (x!=0);
  31. }
  32. if (no==0)
  33. printf("the division cannot be made");
  34. else
  35. d=table[0]/table[1]/table[2]/table[3];
  36. printf("the division is %f", d);
  37.  
  38.  
  39.  
  40. system("pause");
  41. }

plz help me solving this, i spent almost a week thinking about it
thank u for ur help
Last edited by Ancient Dragon; Mar 10th, 2008 at 11:01 pm. Reason: removed color tags and added code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: help!! problems with loops

 
-1
  #2
Mar 10th, 2008
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #define n 4
  5.  
  6. void main()
  7. {
  8. //variables
  9.  
  10. float table[n];
  11. int no=1,i;
  12. float x=0;
  13. float d;
  14. clrscr();
  15. //program
  16. for (i=0; i<n; i++)
  17. {
  18. printf("Enter the number %d : ", i);
  19. scanf("%f", &table[i]);
  20. }
  21. for (i=0; i<n; i++)
  22. {
  23. if(x==0 && i!=0)
  24. no=0;
  25. else
  26. x=table[i];
  27. }
  28. if (no==0)
  29. printf("\nThe division cannot be made");
  30. else
  31. {
  32. d=table[0];
  33. for(i=1;i<n;i++)
  34. d=d/table[i];
  35. printf("\nThe division is %f ", d);
  36. }
  37. getch();
  38. }
It will Help you !
Last edited by Ancient Dragon; Mar 10th, 2008 at 11:01 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 97
Reputation: plgriffith is an unknown quantity at this point 
Solved Threads: 6
plgriffith plgriffith is offline Offline
Junior Poster in Training

Re: help!! problems with loops

 
0
  #3
Mar 10th, 2008
Try using periods every once in a while.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 70
Reputation: bwjones is an unknown quantity at this point 
Solved Threads: 1
bwjones bwjones is offline Offline
Junior Poster in Training

Re: help!! problems with loops

 
0
  #4
Mar 10th, 2008
Originally Posted by plgriffith View Post
Try using periods every once in a while.
Maybe english isn't her primary language?
Last edited by bwjones; Mar 10th, 2008 at 7:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,031
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: help!! problems with loops

 
0
  #5
Mar 10th, 2008
Originally Posted by bwjones View Post
Maybe english isn't her primary language?
Regardless, it is still a good suggestion.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: help!! problems with loops

 
0
  #6
Mar 11th, 2008
Originally Posted by Majestics View Post
It will Help you !
Why this is bad help:
1) No CODE tags
2) No formatting, code is very difficult to read. See this
3) #include<conio.h> -- not portable. Do not use.
4) void main() -- see this
5) clrscr(); -- only 1 compiler defines this function - do not use
6) getch(); -- not portable. Use standard C instead, like getchar()
barbiegirl,
Please explain what you want in detail. Your explanation is lacking in data necessary to understand your problem. Did you read the post titled Read Me: Read This Before Posting?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: help!! problems with loops

 
0
  #7
Mar 11th, 2008
I have given this program only to develop your logic ,it is not a standard form .
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: help!! problems with loops

 
0
  #8
Mar 11th, 2008
Originally Posted by Majestics View Post
I have given this program only to develop your logic ,it is not a standard form .
And where in your original post did you explain that? So how is the person you're trying to help going to know your program is only a logic lesson? And with all the problems, how is he going to know what is good and what is bad since he's new to programming?

IOW, don't help people by showing bad code because it's confusing and does more harm than good. Show an algorithm rather than code if you can't post good stuff. For one, they can learn more from a good algorithm. And, secondly, they can't turn your work to get a good grade. They have to still write it themselves.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 108
Reputation: Majestics is an unknown quantity at this point 
Solved Threads: 7
Majestics Majestics is offline Offline
Junior Poster

Re: help!! problems with loops

 
0
  #9
Mar 11th, 2008
Well......... I know its a mistake but i want her to study these things , every time u cannot write what is going on and what is not , and if a person use 1% of his/her brain he/she can know what does that mean ............
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 10
Reputation: barbiegirl is an unknown quantity at this point 
Solved Threads: 0
barbiegirl's Avatar
barbiegirl barbiegirl is offline Offline
Newbie Poster

Re: help!! problems with loops

 
0
  #10
Mar 12th, 2008
i'm thankful to everyone, it was very helpful
I'm a Barbie Girl, in a Barbie world, life in plastic, it's fantastic, you can brush my hair, undress me everywhere, Imagination, Life is your creation
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC