Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Anti-Loopist's Answer to 1+2+3...
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NewHydrolisk




PostPosted: 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!



Number 4.zip
 Description:
This is Number 4.

Download
 Filename:  Number 4.zip
 Filesize:  77.89 KB
 Downloaded:  407 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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? Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
NewHydrolisk




PostPosted: 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




PostPosted: 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




PostPosted: 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? Confused
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: 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




PostPosted: 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




PostPosted: 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?!
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
NewHydrolisk




PostPosted: 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




PostPosted: 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: ";
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
NewHydrolisk




PostPosted: 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. Confused
michaelp




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: