954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help!! problems with loops

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

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define n 4

void main()
{
                //variables

	double table[n]={0};
	long no=1,i;
	double x=0,d;

                //program
	for (i=0; i<n; i++)
	{
	printf("enter the number %d", i);
	scanf("%f", &table[i]);
	}
	printf("gr8\n");
	printf("%f", table[0]/table[1]);//this is just to c if it works
	for (i=0; i<n; i++)
	{
		do
		{
			if(x==0)
			no=0;
			x=table[i+1];
		}
		while (x!=0);
	}
	if (no==0)
		printf("the division cannot be made");
	else
		d=table[0]/table[1]/table[2]/table[3];
		printf("the division is %f", d);



	system("pause");
}


plz help me solving this, i spent almost a week thinking about it
thank u for ur help

barbiegirl
Newbie Poster
10 posts since Mar 2008
Reputation Points: 25
Solved Threads: 0
 
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define n 4

void main()
{
//variables

float table[n];
int no=1,i;
float x=0;
float d;
clrscr();
//program
for (i=0; i<n; i++)
{
printf("Enter the number %d : ", i);
scanf("%f", &table[i]);
}
for (i=0; i<n; i++)
{
if(x==0 && i!=0)
no=0;
else
x=table[i];
}
if (no==0)
printf("\nThe division cannot be made");
else
{
d=table[0];
for(i=1;i<n;i++)
d=d/table[i];
printf("\nThe division is %f ", d);
}
getch();
}

It will Help you !

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 

Try using periods every once in a while.

plgriffith
Junior Poster
100 posts since Feb 2008
Reputation Points: 10
Solved Threads: 6
 
Try using periods every once in a while.


Maybe english isn't her primary language?

bwjones
Junior Poster in Training
70 posts since Jul 2005
Reputation Points: 10
Solved Threads: 1
 
Maybe english isn't her primary language?


Regardless, it is still a good suggestion.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 
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 ?

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

I have given this program only to develop your logic ,it is not a standard form .

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 
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 turnyour work to get a good grade. They have to still write it themselves.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 

i'm thankful to everyone, it was very helpful:)

barbiegirl
Newbie Poster
10 posts since Mar 2008
Reputation Points: 25
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You