Project 1999

Go Back   Project 1999 > General Community > Off Topic

Closed Thread
 
Thread Tools Display Modes
  #21  
Old 04-27-2011, 12:55 AM
Ihealyou Ihealyou is offline
Sarnak

Ihealyou's Avatar

Join Date: Apr 2010
Location: Cleveland, OH
Posts: 454
Send a message via AIM to Ihealyou
Default

One night I was out drinking. Being a model student, I decided to work on a c++ project when I got home. That night, I went to bed proud of all the work I accomplished. The next morning, I spent about 2 hours fixing all the typos and dumb code that I wrote the night before. That's when I decided that any language which doesn't allow you to code drunk is a piece of shit that overcomplicates simple tasks.
__________________


Uuur - Your favorite Master +1 cleric <LifeAlert>
Rockwell - Your favorite 30 virgin <Aspen and Rockwell>
  #22  
Old 04-27-2011, 01:09 AM
Ruinous Ruinous is offline
Sarnak


Join Date: May 2010
Posts: 277
Default

Step 1: Buy beer.
Step 2: Get drunk.
Step 3: Write everything in Pseudocode.
Step 4: Translate to regular code while sober.
Step 5: .....
Step 6: Profit

Or... experiment more with Ballmer's Peak
  #23  
Old 04-27-2011, 01:48 AM
Null Null is offline
VIP / Contributor

Null's Avatar

Join Date: Apr 2011
Posts: 256
Default

[You must be logged in to view images. Log in or Register.]
  #24  
Old 04-27-2011, 02:17 AM
JayDee JayDee is offline
Planar Protector

JayDee's Avatar

Join Date: Oct 2009
Posts: 1,628
Default

Angwe is back in business
__________________
  #25  
Old 04-27-2011, 04:22 PM
Divarin Divarin is offline
Kobold


Join Date: Jul 2010
Posts: 113
Default

here's a simple way to do part 1 without the need for an array
Code:
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int count, min, max, total;
	count=0;
	total=0;

	cout << "Please enter 5 numbers seperated by a space\n";
	while ( count < 5 )
	{
		int number;
		cin >> number;
		count++;
		if ( 1 == count )
		{
			min=number;
			max=number;
		}
		else
		{
			if ( number < min )
				min = number;
			if ( number > max )
				max = number;
		}
		total += number;
	}

	cout << " Lowest: " << min << endl 
		 << "Highest: " << max << endl
		 << "Average: " << total/5 << endl;
	
	system("pause");

	return 0;
}
  #26  
Old 02-24-2012, 03:37 PM
Truth Truth is offline
Banned


Join Date: Nov 2011
Location: h00t
Posts: 842
Send a message via ICQ to Truth Send a message via AIM to Truth Send a message via MSN to Truth Send a message via Yahoo to Truth
Default Dangling Pointer = Fallacy

So I have never used smart/auto pointers or seen them used in any production code. One of the big woops about them is that when you copy addresses it nulls the first pointer so you can't dangle it. So I was like man let's see if its a big woop after all.

PHP Code:
#include <stdio.h>
int main(int argccharargv[])
{
    
int *p1 = new int(5);
    
int *p2 p1;
    
delete p1;  // recycle heap cell... p2 is now a dangling pointer

    
*p2 420// segmentation fault imqo
    
printf("%p = %d\n"p2, *p2);  // but wait... 0x14dc010 = 420?????

    
p1 0x0// set address of p1 to null
    
printf("%p = %d"p1, *p1); // good. generates segmentation fault error...

    
return 0;

maybe more complex example is needed to throw off the compiler?? I even compiled with optimization off cuz i thought it would be just removing the delete line since we use it right after
Code:
r00t@wutdo:~/dangling$ g++ -g -O0 -fno-inline main.cpp
r00t@wutdo:~/dangling$ ./a.out
0x24d5010 = 420
Segmentation fault
wut da fuk
Last edited by Truth; 02-24-2012 at 03:57 PM.. Reason: nerdalert
Closed Thread


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:38 PM.


Everquest is a registered trademark of Daybreak Game Company LLC.
Project 1999 is not associated or affiliated in any way with Daybreak Game Company LLC.
Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.