-
my Code
ok, i'm trying to learn C++ i don't have any background on Developing languges (if you count HTML and CSS are than i'm only decent at those) so this is my code:
Code:
#include <iostream>
using namespace std;
int main()
{
int x
int y
cout<<"please write this number: ";
cin>> x;
cin.ignore();
cout<<"please re-write the number: ";
cin>> y;
if (x == y) {
cout<<"indeed, you have a good memory sir";
}
if ( x != y) {
cout<<"sir, you have a bad memory";
}
cin.get();
}
ok don't flame me, this is my first program ever im making on my own! so i'm trying to make a program where you enter the same number twice, but it doesn't work.. i know there's some huge mistake.. so can someone help me out?
-
You'll need semi-colons after you declare your integers.
Also, it's good that you're formatting your code with tabs and things, but you might want a system that's a little easier on the eyes in the future.
-
what the..? Wow Thanks a Lot!!
EDIT: hmm.. it works, but it doesn't work when i put the numbers, right or wrong, the program just closes.. i did some modifications:
Code:
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
cout<<"please write a number: ";
cin>> x;
cin.ignore();
cout<<"please re-write the number: ";
cin>> y;
if (x == y) {
cout<<"indeed, you have a good memory sir\n";
}
else {
cout<<"sir, you have a bad memory\n";
}
}
can some one help? again? sorry...
-
you can either stick cin.get(); at the end (which you did in your first post, why did you change it?), or run it from the DOS prompt/konsole or whatever you're using.
-
The closing of the console is a common question. In your case, if you add back the cin.get() you'll still need a cin.ignore() before it and after your last call to cin >>.
-
thanks, fixed it!
it needed a cin.get(); and a cin.ignore();
Cool! it's Complete now!