C++ help

Posts 18 of 8 · Page 1 of 1
C++ help
So Im hoping Im posting in the right section and everything but I figured since I need to learn c++ to code hacks I could get some help here with a fairly simple program....
Im using vs 2008 and I have no problem compiling this program however I do have a problem during runtime the program wont always throw an error when allocating memory sometimes it just freezes but I have no clue why.... Any help is appreciated thanks in advance i iz dumb

my code:
//Start of code
//
//Start define
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <new>
using namespace std;
//End define
//
//Start functions used in main
//
//Makelist function begin
int* makelist (int a)
{
cout << "Initializing memory for operation, please wait...\n";
int * lenghth;
lenghth = new (nothrow) int [a];
if (lenghth == 0)
{
cout << "ERROR ALLOCATING MEMORY!\n";
return 0;
}
cout << "Done!\n";
return(lenghth);
}
//Makelist function end
//
//Pause function begin
void pause ()
{
cin.ignore();
cin.get();
}
//Pause function end
//
//Start function clearmem
void clearmem (int * addy, int lenghth)
{
cout << "Freeing memory please wait...\n";
delete[lenghth] addy;
cout << "Done!\n";
}
//End function clearmem
//
//End functions used in main
//
//Start main
int main()
{
int a;
int a_const;
int * list_location;
cout << "Enter the number of numbers you want to find in the Fibonaci sequence.\n";
cin >> a;
a_const = a;
if (a == 0)
{
cout << "Ummmm so you started this program to not use it.... im not going\nto calculate the 0th number -.-\npress enter to close...";
pause();
return 0;
}
list_location = makelist (a);
clearmem(list_location, a_const);
pause();
return 0;
}
//End main
//
//End code

EDIT: The last thing shown in console is "Initializing memory for operation, please wait..." then it usually freezes the strange thing is up to 999999999 it just fails to initialise and throws the error message up but when there are 10 digits then it freezes.... I dont know of any explanation for this.... help please :/
Your code is practically unreadable (on my mobile right now). Please add spacing / indenting to your code.
Hmmm when I edit it it comes out right gah I really wish I could post a text file somewhere and link it..... :/
That is against the rules? Or am I being paranoid? I will pm you a link to the txt file perhaps if you can use it?
Quote Originally Posted by hobosrock696 View Post
Hmmm when I edit it it comes out right gah I really wish I could post a text file somewhere and link it..... :/
That is against the rules? Or am I being paranoid? I will pm you a link to the txt file perhaps if you can use it?
Wrong section, this should go in the C++ section, it has nothing to do with Combat Arms Coding..
I'm sorry but really, that needs a lot of work. I cant even read that. It looks like you packed everything in to one little line.
Use code tags, and like they said, if we can't read it we can't help.
I apologize could you please demonstrate a small chunk of code properly formatted?
Quote Originally Posted by hobosrock696 View Post
I apologize could you please demonstrate a small chunk of code properly formatted?
[php]//Start of code
//Start define
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <new>

using namespace std;
//End define
//
//Start functions used in main
//
//Makelist function begin
int* makelist (int a)
{
cout << "Initializing memory for operation, please wait...\n";
int * lenghth;
lenghth = new (nothrow) int [a];

if (lenghth == 0)
{
cout << "ERROR ALLOCATING MEMORY!\n";
return 0;
}

cout << "Done!\n";
return(lenghth);
}[/php]
Posts 18 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?