Blaylok's Profile User Rating: -----

Reputation: -2 Dishonored
Group:
New Members
Active Posts:
7 (0.01 per day)
Joined:
19-August 12
Profile Views:
648
Last Active:
User is offline Apr 29 2013 09:00 AM
Currently:
Offline

Previous Fields

Country:
IN
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Icon   Blaylok has not set their status

Posts I've Made

  1. In Topic: C++ do while loop not working right

    Posted 4 Oct 2012

    View PostSkydiver, on 04 October 2012 - 08:44 PM, said:

    Please do not encourage people to use goto's. That could have have been written using a do-while loop like the original code.


    I used the goto statement because the do while statement somehow did not work, and the while statement was not the best one for that.
  2. In Topic: C++ do while loop not working right

    Posted 4 Oct 2012

    Hold on... Just chillax!! I'll help you out! :D

    The right way for the condition is putting && between the conditions. This is because, -1 will be less than 100, so one of the conditions will result true and the other will be false. So if you put || instead of && then the loop will take numb as -1. But if we put &&, then both conditions have to be satisfied. So the loop will again ask for the number.

    Now, I tried with &&, but this loop still behaves in the same way. So it is better to write with an if condition.

    
    INPUT:
      cout << "Enter an integer between 1 and 100" << endl;
      cin >> numb;
    
    	if(!((numb>=1)&&(numb<=100)))
    	{
    		goto INPUT;
    	}
    
    
    


    This works perfectly. But I think it wont show the correct answer as there are more errors following it.

    |I| for (j=numb; j>=0; j++)

    This will lead you to infinite loop. As j (numb) will always be greater than 0! So the condition you should put is:

    for (j=numb; j<=100; j++) //or j=j+1 (in the updation statement
    


    |II| cout <<"\n <<j<< " << endl;

    I have no idea what you are trying to do in this statement. But if you want to show the value of j every time then it should have been

     cout << "\n" << j << endl; 
    


    |III| sum = sum - j;

    It should be sum = sum + j;. We are adding numbers and not subtracting.

    ------------------------------------------

    So, I'll give you a corrected one.

    #include <iostream.h>
    
    int main()
    {
    
      int j, numb, sum;
    
      INPUT:
      cout << "Enter an integer between 1 and 100" << endl;
      cin >> numb;
    
    	if(!((numb>=1)&&(numb<=100)))
    	{
    		goto INPUT;
    	}
    
      sum = 0;
     
      for ( j=numb; j<=100; j=j+1 )
    
    	 {
    
    	     cout <<"\n"<< j << endl;
    
    	     sum = sum  + j;
    
    	 }
    
    	 cout << "\n Sum = " << sum << endl;
    
    
    
    	 cin.get();
    
    }
    
    
    
  3. In Topic: What are you working on today?

    Posted 3 Oct 2012

    Well... I'm working on an OS. I have just designed the basic kernel of it. It'll be like a Quad-Core Kernel, with 4 different parts working independently so that we get the maximum speed from the software part. Now I'm working with it's coding part! :D

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Full Name:
Naveen Venkat
Years Programming:
3
Programming Languages:
VB6, C++, HTML

Contact Information

E-mail:
Private

Friends

Blaylok hasn't added any friends yet.

Comments

Blaylok has no profile comments yet. Why not say hello?