Author |
Message |
NewHydrolisk
|
Posted: Fri Oct 26, 2007 7:19 pm Post subject: Anti-Loopist's Answer to 1+2+3... |
|
|
My fourth project, and the only that works properly (so far).
This is my first project submitted here though.
It simply does a 1+2+3+4...+100 thing, but you can pick the numbers it starts and ends at. Perhaps it is faster than a loop.
It's less than an MB, and the formula used is inside the program.
I don't think bugs are possible...
You need Windows (because I use Windows, but only because of the "system(Pause)" command at the end). Sorry other OS users!
Description: |
|
Download |
Filename: |
Number 4.zip |
Filesize: |
77.89 KB |
Downloaded: |
418 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
md
|
Posted: Fri Oct 26, 2007 8:49 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
No source code? I would recommend no one run this unless source is provided, and even then I'd compile it myself.
|
|
|
|
|
|
NewHydrolisk
|
Posted: Fri Oct 26, 2007 9:50 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Oops. Sorry. I'll post
Alright, since this is my first time here (submitting), I wasn't very sure what to put.
In the ZIP, there is a readme with the source code.
By the way, it was written in C++.
|
|
|
|
|
|
md
|
Posted: Fri Oct 26, 2007 9:56 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
No problem, I'm just very anti-executables. Mostly since a) they are platform dependent and b) it's super easy to hide a virus in an executable. It's harder in source code.
|
|
|
|
|
|
Tony
|
Posted: Sat Oct 27, 2007 1:01 am Post subject: Re: Anti-Loopist's Answer to 1+2+3... |
|
|
NewHydrolisk @ Fri Oct 26, 2007 7:19 pm wrote: You need Windows (because I use Windows, but only because of the "system(Pause)" command at the end). Sorry other OS users!
You don't really need system(Pause), do you?
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
NewHydrolisk
|
Posted: Sat Oct 27, 2007 7:18 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Well, I used Visual Basic C++, and when I compiled it, the program exited immediately after you entered the first 2 numbers, which sort of drove me off the edge of sanity, and so I bashed it in because of my impatience. (Was trying to find an answer for 2 days...)
|
|
|
|
|
|
rdrake
|
Posted: Sat Oct 27, 2007 8:08 pm Post subject: Re: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
NewHydrolisk @ Sat Oct 27, 2007 7:18 pm wrote: Well, I used Visual Basic C++ Visual C++?
|
|
|
|
|
|
Clayton
|
Posted: Sat Oct 27, 2007 10:39 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Whatever happened to just making an executable and executing from the command line?
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Sat Oct 27, 2007 10:49 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Not enough bling value. IDEs are the twenty inch chrome rims of the programming world.
|
|
|
|
|
|
wtd
|
Posted: Sat Oct 27, 2007 10:51 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Note: I am still not seeing code.
|
|
|
|
|
|
Tony
|
Posted: Sat Oct 27, 2007 11:29 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
the chrome is rusty, the program still fires up cmd for the duration of its life. Where's DirectX with the flare effect?!
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
NewHydrolisk
|
Posted: Sun Oct 28, 2007 11:50 am Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
Source Code Below:
code: | #include <iostream>
using namespace std;
int main()
{
int b, c;
cout << "(If it isn't completely numerical, the answer will be varying.)\n(The answer will also vary if the numbers are too large.)" << endl;
cout << "This was created and coded by Luang Cui." << endl;
cout << "Thanks to my father for the mathematical formula." << endl;
cout << "Please, enter a smaller integer first, then a larger integer." << endl;
char question[] = "First integer: ";
int a;
cout << question;
cin >> a;
char question2[] = "Second integer: ";
int d;
cout << question2;
cin >> d;
if (a<d)
{
char answer[] = "Output, ";
b= d;
c= ((a + b) * ((b - a) + 1)) / 2;
cout << answer << c << "." << endl;
cout << "The output is reached by a special mathematical formula." << endl;
cout << "The pattern adds 1 to the smaller integer continuously until the next integer is equal to the larger integer." << endl;
cout << "EXAMPLE: 1+2+3...+100." << endl;
cout << "The formula is: {(X+Y)*[(Y-X)+1]}/2, where X is the smaller integer and Y is the larger." << endl;
}
else
{
cout << "The first integer is larger than or equal to the second!" << endl;
}
system("PAUSE");
return 0;
} |
Alright, that's the source.
C++
|
|
|
|
|
|
Tony
|
Posted: Sun Oct 28, 2007 1:48 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
It compiles and runs wonderfully on OS X, but it throws a warning when it gets to the Pause line -- you should really take that out.
Quote:
sh: line 1: PAUSE: command not found
also - what's the reasoning behind
code: |
char question[] = "First integer: ";
cout << question;
|
why not just
code: |
cout << "First integer: ";
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
NewHydrolisk
|
Posted: Sun Oct 28, 2007 7:46 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
I'm not sure myself why I had code: | char question[] = "First integer: "; | in there.
Thanks for the... hint thing though.
EDIT: I remember... I was following a tutorial, and so I had just put that there... Damn, I'm not too smart.
|
|
|
|
|
|
michaelp
|
Posted: Sun Feb 03, 2008 9:38 pm Post subject: RE:Anti-Loopist\'s Answer to 1+2+3... |
|
|
If you use Code::Blocks as your IDE, it might automatically put a stop line in your code. Whenever I run it from the IDE, it stops and says how long it was up.
|
|
|
|
|
|
|