Follow us on Twitter!
Become the change you seek in the world. - Gandhi
Monday, April 21, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 23
Guests Online: 21
Members Online: 2

Registered Members: 82856
Newest Member: djtonyg
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

help with a loop (C++)


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-10-06 01:49
hey guys, i need a little help. Below you can see my code for a program to factor equations but as you can see there is no loop, i need some help with what kind of loop to use and some tips on writing it. If this isnt descriptive enough just tell me and ill try to explain better.

thanks,



#include <iostream.h>
main()
{
int a;
int b;
int c;
int x=1;
int y;
cout<<"enter value for b"<<endl;
cin>>b;
cout<<"enter value for c"<<endl;
cin>>c;
system("pause" );
x++;
y=c/x;
if(x+y==b );
{
cout<<" x equals "<<x<<" "<<" y equals "<<y<<endl;
system("pause" );
}

}



Author

RE: help with a loop (C++)


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-10-06 02:54
You can find an explanation for loops at practically any site that offers tutorials on C++...but what I used here is called a while loop. WHILE a certain condition is TRUE execute this code.

Code

#include <iostream>
#include <string>
using namespace std;

int main()
{
int a;
int b;
int c;
int x=1;
int y;
while(1)
{
cout<<"enter value for b"<<endl;
cin>>b;
cout<<"enter value for c"<<endl;
cin>>c;
system("pause" );
x++;
y=c/x;
if(x+y==b );
{
cout<<" x equals "<<x<<" "<<" y equals "<<y<<endl;
cout << "Would you like to do another equation? (Y or N)" << endl;
cout << "Default action is to repeat." << endl;
cout << "Request: ";
string z;
cin >> z;
if (z == "Y" || z == "y")
{
      continue;
      }
else if(z == "N" || z == "n")
{
      exit(1);
      }
else
{
     continue;
     }
}
}
}






Author

RE: help with a loop (C++)


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-10-06 16:35
Wow, you guys are messy. =P

Code

#include <iostream>

int main(int argc, char **argv)
{
      unsigned int uB, uC, uX = 1, uY;
      char chRestart;
      bool bQuit = false;

      do
      {
           std::cout << "Enter the value for b: ";
           std::cin >> uB;
           std::cout << "Enter the value for c: ";
           std::cin >> uC;

                ++uX;
                uY = uC / uX;
                if(uX + uY == uB)
                {
                        std::cout << "x is equal to: " << uX
                                        << " and y is equal to: " << uY << std::endl;
                        std::cout << "Would you like to perform another operation? "
                                        << "(Y) or (N) : ";
                        std::cin >> chRestart;
                        bQuit = (chRestart == 'Y' || chRestart == 'y') ? false : true;
                }
        } while(!bQuit);

        return 0;
}





Edited by on 21-10-06 16:42