tblackma222
Registered
Hi. I've just started using Xcode to write c++ program. The program below compiles fine and runs fine, including the "cout" line, until it gets to the "cin >> f" line. I can type in anything and it appears on the screen, but when I hit enter or return, instead of stopping receiving keyboard input, it just goes to the next line. Here's the program:
#include
using namespace std;
int fact(int x)
{
int n = 1;
for(int i = 1; i <= x; n++)
{
n *= i;
}
return n;
}
int main (int argc, const char * argv[])
{
int f;
cout << "Enter the number whose factorial you want: ";
cin >> f;
cout << endl << "The factorial is: " << fact(f) << "." << endl;
return 0;
}
i'm running mac OSX Tiger on a new intel-based macbook pro, and I downloaded Xcode off the apple website, if that's relevant.
Thanks for your help.
#include
using namespace std;
int fact(int x)
{
int n = 1;
for(int i = 1; i <= x; n++)
{
n *= i;
}
return n;
}
int main (int argc, const char * argv[])
{
int f;
cout << "Enter the number whose factorial you want: ";
cin >> f;
cout << endl << "The factorial is: " << fact(f) << "." << endl;
return 0;
}
i'm running mac OSX Tiger on a new intel-based macbook pro, and I downloaded Xcode off the apple website, if that's relevant.
Thanks for your help.