Help me debug my code.
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
}
#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;
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;
#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;
}
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;
}
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;
}
/*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;
}
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...
Nor did you specify that you are using the std namespace.
The error messages you got should be helpful with this...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement