Posted: Thu Apr 28, 2005 8:35 am Post subject: (No subject)
Just take it slow. C++ has a pretty steep learning curve, but it'll all make sense eventually.
Sponsor Sponsor
jamonathin
Posted: Thu Apr 28, 2005 8:46 am Post subject: (No subject)
I've been reading through all of this, and for cornflakes/martin's method, how do you go from the second part to teh first part. I mean, how do you skip the calculator, and jump right to main?
And for wtd, I pretty much understand it, Its just I cant get it to run, I added the
c++:
#include <iostream> #include <string>
But are there any others I'm missing?
I'm tryin to take it slow, but i just recently realized how far behind I am programming wise, [ lol all i know is turing ]. So that's why I'm really pushin this c++ for me.
Martin
Posted: Thu Apr 28, 2005 9:05 am Post subject: (No subject)
int main is the entry point for the program. Unlike turing which just begins from the top of the code and works its way down, a C++ program starts at the int main method. Calculate() is just a function that you can call.
Posted: Thu Apr 28, 2005 11:10 am Post subject: (No subject)
ohhhhhhhhh, i thought main was like Calculator, just a word, ok thats makes more sense, thanks .
jamonathin
Posted: Thu Apr 28, 2005 11:40 am Post subject: (No subject)
I hope I'm not buggin you guys too much, if I am, just kick me or something.
I was looking through the tutorials, and Hacker Dan suggested to just redo some old turing programs into C++.
I found an example of a for loop in the tuts section, but I can't quite figure it out.
c++:
#include <iostream>
int main () { int n, t = 1;
std::cout << "Enter Any Number.\n";
std::cin >> n;
for(int i = 1; int i < n; i++) {
t *= i;
}
std::cout << "The Result Is " << t;
int wait;
std::cin >> wait;
return0;
}
Also, if anyone knows where a good help file is, (like Turing's F10), can ya tell me about it, cuz I dun wanna annoy you guys. Thanks
EDIT: It's kinda wierd wtd and I posted on the same minute, but on his 2000th post!
wtd
Posted: Thu Apr 28, 2005 11:40 am Post subject: (No subject)
Martin wrote:
int main is the entry point for the program. Unlike turing which just begins from the top of the code and works its way down, a C++ program starts at the int main method. Calculate() is just a function that you can call.
Posted: Thu Apr 28, 2005 11:44 am Post subject: (No subject)
c++:
for(int i = 1; int i < n; i++)
This is your problem.
The first "int" is used to declare the variable "i". Subsequent uses of "i" do not require it. Corrected, it looks like:
c++:
for(int i = 1; i < n; i++)
jamonathin
Posted: Thu Apr 28, 2005 11:52 am Post subject: (No subject)
Something's still wrong though. In Turing, if I enter 4, i get 24, but in this program, i get 6. This is my for loop in Turing.
Turing:
for i :1.. n
t *= i
endfor
Sponsor Sponsor
wtd
Posted: Thu Apr 28, 2005 11:57 am Post subject: (No subject)
In your Turing loop, you say "loop from 1 to n". In the C++ loop you're saying "loop from i = 1 while i is less than n, incremeneting i by one each time".
Thus the loop goes from 1 to 3. To change this, you need to use the less than or equals operator. I'm just using a bit of a different initialization syntax for "i", and I'm using the prefix increment operator.
c++:
for(int i(n); i <= n; ++i)
Martin
Posted: Thu Apr 28, 2005 12:18 pm Post subject: (No subject)
it should be int i (1), not (n).
wtd
Posted: Thu Apr 28, 2005 12:25 pm Post subject: (No subject)
Ah yes.
Martin
Posted: Thu Apr 28, 2005 12:28 pm Post subject: (No subject)
Got your back
wtd
Posted: Thu Apr 28, 2005 12:38 pm Post subject: (No subject)
Martin wrote:
Got your back
That's what I'm afraid of.
jamonathin
Posted: Thu Apr 28, 2005 12:48 pm Post subject: (No subject)
lol . . . works good guys, thanks
wtd
Posted: Thu Apr 28, 2005 12:56 pm Post subject: (No subject)
Congrats on accidentally implementing a factorial function. Now you need only embrace the zen of: