Thread: C++ help

Results 1 to 8 of 8
  1. #1
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow

    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 :/
    Last edited by hobosrock696; 09-02-2010 at 03:46 PM. Reason: forgot to post where it stops

  2. #2
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,035
    Reputation
    340
    Thanks
    2,784
    My Mood
    Sad
    Your code is practically unreadable (on my mobile right now). Please add spacing / indenting to your code.

  3. #3
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    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?
    Last edited by hobosrock696; 09-02-2010 at 03:53 PM.

  4. #4
    _-Blazin-_'s Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    Australia
    Posts
    428
    Reputation
    10
    Thanks
    28
    My Mood
    Hot
    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..

  5. #5
    Carlo Cn's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    11
    Reputation
    10
    Thanks
    0
    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.

  6. #6
    LightzOut's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    185
    Reputation
    11
    Thanks
    25
    Use code tags, and like they said, if we can't read it we can't help.

  7. #7
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    I apologize could you please demonstrate a small chunk of code properly formatted?

  8. #8
    markoj's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    s
    Posts
    1,067
    Reputation
    60
    Thanks
    407
    My Mood
    Bored
    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]
    Dont ban me

Similar Threads

  1. [Help Request] Combat arms Vid help
    By djw111 in forum Combat Arms Help
    Replies: 4
    Last Post: 12-24-2011, 06:06 PM
  2. [Help Request] AFK Bot [help]
    By fet in forum Combat Arms Help
    Replies: 7
    Last Post: 04-28-2011, 04:17 AM
  3. [Help Request] Injector Admin help
    By asdfgas in forum Combat Arms Help
    Replies: 4
    Last Post: 04-27-2011, 07:12 PM
  4. [Help Request] Ajuda / Help
    By - Battery' in forum Combat Arms BR Coding Help
    Replies: 3
    Last Post: 04-22-2011, 08:15 PM
  5. [Help Request] Help my!
    By Windowns7 in forum Combat Arms BR Coding Help
    Replies: 2
    Last Post: 04-18-2011, 02:41 PM