Jump to content
  • Advertisement
Sign in to follow this  
Coop56

Help me debug my code.

This topic is 5068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Some errors, and I'm not sure whats wrong. /*Write a single if statement that examines two integer values and changes the larger to the smaller, using only one else clause.*/ #include <iostream> int main () { int x, y; cout << "Please enter two numbers.\n"; //giving error on this line cout << "First: \n"; cin >> x; //and this line cout << "Second: \n"; cin >> y; if (x > y) x = y; else y = x; cout >> "X: " >> x; return 0; System("pause"); //and here }

Share this post


Link to post
Share on other sites
Advertisement
#include <iostream>
using namespace std; // <- important, and most likely what the compiler wants.

using namespace std, in simplified terms, explains where cout and cin are. That is, a part of std (standard.)

[edit]

Also, cout >> "X: " >> x; has the wrong operator. You want cout << "X: " << x;

Share this post


Link to post
Share on other sites
#include <iostream>
using namespace std;
int main ()

{
int x, y;

cout << "Please enter two numbers.\n"; //giving error on this line
cout << "First: \n";
cin >> x; //and this line
cout << "Second: \n";
cin >> y;

if (x > y)
x = y;

else
y = x;

cout << "X: " << x;

cout<<"Press any key to quit";
string exit;
cin>>exit; cout<<"Thanks";

return 0;
}

Share this post


Link to post
Share on other sites
Revised code



/*Write a single if statement that examines two integer values and changes the
larger to the smaller, using only one else clause.*/

#include <iostream>
using namespace std;

int main ()

{
int x, y;

cout << "Please enter two numbers.\n";
cout << "First: \n";
cin >> x;
cout << "Second: \n";
cin >> y;

if (x > y)
x = y;

else
y = x;

cout >> "X: " >> x; //just giving an error here now
cout<<"Press any key to quit";
string exit;
cin>>exit;
cout<<"Thanks";
return 0;

}

Share this post


Link to post
Share on other sites
Well, you did not include stdlib.h for the System call.

Nor did you specify that you are using the std namespace.

The error messages you got should be helpful with this...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!