3 Replies - 437 Views - Last Post: 22 August 2019 - 10:07 PM Rate Topic: -----

#1 beginnerC++   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-August 19

white loop .Error

Posted 22 August 2019 - 09:00 AM

#include <iostream>

using namespace std;

int main()
{
    int n=0,twopowern, count;
    while(n<7)
    {
        if(n==0)
            twopowern=1;
        else
            twopowern=1;
            count=1;
            while(count <=n)
            {
                twopowern=twopowern*2;
                count = count + 1;
            }
    }

if(twopowern<10){

    cout<<n<<" " <<twopowern<<endl;
}
else{

    cout<<n<<" " << twopowern<<endl;
   n = n + 1;
}

return 0;
}




I actually do not know what is the error, when i hit f9 to see it is runs, the window opens but does not show anything. In fact i tried to type something in and it is all white. it is really weird. I read the problem in the book and tried to solve it myself but i guess something must be wrong. the exercise will display two columns, in which the first one is "n" and the second column would be 2 to the power n.
any help would be appreciated . Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: white loop .Error

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,171
  • Joined: 12-June 08

Re: white loop .Error

Posted 22 August 2019 - 09:03 AM

Lines 8-20. When does the variable 'n' ever change? If the variable never changes the loop is never ending. That is a problem.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: white loop .Error

Posted 22 August 2019 - 06:14 PM

beginnerC++: It will also help you and others who read your code if you following an indentation style and apply it consistently.

Here's your code indented the way I like to see code. You may have your own preferences. It doesn't matter what it is, but apply it consistently.

#include <iostream>

using namespace std;

int main()
{
    int n = 0;
    int twopowern = 0;

    while (n < 7)
    {
        if (n == 0)
            twopowern = 1;
        else
            twopowern = 1;

        int count = 1;
        while(count <= n)
        {
            twopowern = twopowern * 2;
            count = count + 1;
        }
    }

    if (twopowern < 10)
    {
        cout << n <<" " << twopowern << endl;
    }
    else
    {
        cout << n << " " << twopowern << endl;
        n = n + 1;
    }

    return 0;
}


Was This Post Helpful? 1
  • +
  • -

#4 webchefz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-August 19

Re: white loop .Error

Posted 22 August 2019 - 10:07 PM

View Postmodi123_1, on 22 August 2019 - 09:03 AM, said:

Lines 8-20. When does the variable 'n' ever change? If the variable never changes the loop is never ending. That is a problem.


Yea, I have checked. You are right.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1