0

i was told tht from this:

int main () 
{
    int i,j,vsota;
    for (i=1; j=10; i<=j; i++)
{
     vsota=vsota+i+j;
     j--;
}
system ("pause"); 
return 0; 
}

i must make it work with while ;
but the oruginal doesnt work allso
what should i doo??;
please any help;?

#include <iostream> 
using namespace std;

int main () 
{ 
int i = 1,vsota,j; 


while (j=10;i<=j) 
{ 
      vsota = vsota + i + j;
      j--; 
      i++; 
}
system("pause); 
return 0; 

Edited by Nick Evan: Fixed code-tags

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by marh
0

i think it would be better if u initialize j outside while, because first

while (j=10;i<=j)

it will initiliaze j = 10 then test if i <= j. after the first loop has been done,
j will have j-- means j = 9, but then when it meets

while (j=10;i<=j)

j will become 10 again because of the "j = 10"

also i think it would be better too if u initilialize the variable vsota.

0

edited : u shud put the initiliatization outside the loop

while(j=10; i<=j)

change to =

     j = 10;
     while(i<=j)
     {
        //code
     }

and so does the for loop

for (i=1; j=10; i<=j; i++)

change to =

 j = 10;
    for(i = 1; i<= j; i++)
    {

    }

please correct me if im wrong

Edited by Sendy Hipo

0

in the for loop to double initialize use a comman [,] not [;]
the rest I agree with Sedy Hippo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.