- #1
A.J.710
- 53
- 1
I am not sure if this is supposed to go in the homework forum or not since it is more of an off physics topic so sorry if it is incorrect.
I have a programming assignment for class and I am having a lot of trouble with a while loop. For this part of the program I have to prompt the user to enter 4 non zero integers. If one of them is 0 I have to prompt them to re enter the integers. If all of them are 0 the program has to be terminated. I am doing it in a while loop as instructed but I can't get the variable to change when the statement is true.
I am not nearly done. I am just testing for the first variable so far just to get the hang of it.
Here is little section of the program that I cannot get to work. Basically if the first integer entered is 0 it should end the while loop and end the program, if not, it continues with the rest of the program which is basically just adding two rational numbers and finding the GCD to simplify them. (that part is obviously not shown here).
The issue I am having is that "again" never changes to 0 and it just keeps running the rest of the program and then going back to the printf function in the while loop.
int main( )
{
int a, b, c, d, again, azero, pzero;
int num, den, g, sum;
again = 1;
while (again==1)
{
printf("Please enter four non zero integers \n");
scanf("%d %d %d %d",&a, &b, &c, &d);
if ((a=0))
{
again = 0;
}
else
I have a programming assignment for class and I am having a lot of trouble with a while loop. For this part of the program I have to prompt the user to enter 4 non zero integers. If one of them is 0 I have to prompt them to re enter the integers. If all of them are 0 the program has to be terminated. I am doing it in a while loop as instructed but I can't get the variable to change when the statement is true.
I am not nearly done. I am just testing for the first variable so far just to get the hang of it.
Here is little section of the program that I cannot get to work. Basically if the first integer entered is 0 it should end the while loop and end the program, if not, it continues with the rest of the program which is basically just adding two rational numbers and finding the GCD to simplify them. (that part is obviously not shown here).
The issue I am having is that "again" never changes to 0 and it just keeps running the rest of the program and then going back to the printf function in the while loop.
int main( )
{
int a, b, c, d, again, azero, pzero;
int num, den, g, sum;
again = 1;
while (again==1)
{
printf("Please enter four non zero integers \n");
scanf("%d %d %d %d",&a, &b, &c, &d);
if ((a=0))
{
again = 0;
}
else