Jump to content


Check out our Community Blogs

MeTh0Dz

Member Since 28 May 2008
Offline Last Active May 08 2018 03:49 PM
-----

#553900 Whhat is wrong with this isdigit

Posted by MeTh0Dz on 28 April 2010 - 10:44 AM

Here is my solution :D

#include <iostream>

using namespace std;

int main()
{
    char number;

    while (cin >> number)
    {
        if (number > 57 || number < 48)
            cout << number << " Is not an integer!" << endl;
        else
            return 0;
    }

}



or you can always do it the other way around :D exit if it does not enter an integer!

#include <iostream>

using namespace std;

int main()
{
    int number;

    while (cin >> number)
        cout << number << " Is an integer!" << endl;

    cout << "The last input is not an integer!" << endl;

    return 0;
}


The first solution is bad because it's platform dependent. You are assuming that the charset is going to be ascii. This is a bad thing to assume.

The second 'solution' is bad because it doesn't even attempt to do what the OP asked for.
  • -1


#542419 algorithms based on probability theory and statistics

Posted by MeTh0Dz on 13 February 2010 - 12:30 AM

You should not be trying to get input on your graduate thesis from a programming forum.
  • -1


#539692 Very Simple Question for all

Posted by MeTh0Dz on 01 February 2010 - 02:39 PM

Hey dude, are names numbers?
  • -1


#418522 LOL - Is Your Son a Computer Hacker?

Posted by MeTh0Dz on 23 December 2008 - 09:26 AM

Known satire.

As well as the elite-hackers site.
  • 1


#415558 Game Loop - Need some help looping..

Posted by MeTh0Dz on 13 December 2008 - 06:45 AM

Lance it's obvious that you don't know much about the language through a paradigm standpoint so saying that you wouldn't hesitate to do something doesn't mean much.

Where it's logical? It makes much more sense to just use a while loop and eliminate your do-while and jmp. Also stop acting like it's cool to disagree with Bjarne. It's annoying.

Also that is terrible reasoning. There are tons of things in C++ you shouldn't use. Macros, C style strings (usually), C syle [File]IO, void pointers, etc.
  • -1


#394741 New to programming - First language?

Posted by MeTh0Dz on 13 October 2008 - 03:17 AM

Just use SciTE or ViM plus Gcc suite and you'll be good.

I actually wrote myself a project manager for SciTE, which I could post if anyone wanted.
  • 1


#390533 Need really quick help on passing function

Posted by MeTh0Dz on 05 October 2008 - 01:51 PM

Hawk1, tell me EXACTLY, what your code should do.

And I will code you a proper implementation.
  • 1


#388952 Can someone point the mistake... C

Posted by MeTh0Dz on 02 October 2008 - 10:06 AM

/* My implementation of ls */

#include <iostream>

#include <sys/types.h>

#include <dirent.h>



using namespace std;



int LS_implementation(char * directory);

void Print_Failed(char ** failed);



int main(int argc, char ** argv) {

	int i = 1;

	int j = 0;

	char ** fail_list = (char**)calloc(sizeof(char),  30); // Allocate some zeroed out memory

	while (argv[i] != NULL) {  // Check that something was entered and loop while something remains

		if (LS_implementation(argv[i]) == -1) { // Do the function 

			fail_list[j] = argv[i];  // If it fails add the value to the failed list

			j++;  // then increase j so that we can increase our position in the pointer

		}

		i++;

		cout << endl;

	}

	Print_Failed(fail_list);  // print the failed list

	free (fail_list);

	return 0;

}

int LS_implementation(char * directory) {

	DIR * opened_dir;

	struct dirent * directory_structure;

	

	opened_dir = opendir(directory);  // open the directory return -1 on failure

	if (opened_dir == NULL) {

		return -1;

	}

	

	cout << "Directory: " << directory << endl;

	

	while (1) {

		directory_structure = readdir(opened_dir);  // read the contents of the diretory

		if (directory_structure == NULL) {   // stop reading when NULL is returned (the end)

			closedir(opened_dir);

			return 0;

		}

		cout << directory_structure->d_name << endl;

	}

	

	

	return 0;

}



void Print_Failed(char ** failed) {

	while (*failed != NULL && failed != NULL) { // Check that the address and whatever is being pointed 

		cout << "Failed: " << *failed << endl;  // to isn't NULL, then if not print

		failed++;

	}

}


  • 1


#388945 Can someone point the mistake... C

Posted by MeTh0Dz on 02 October 2008 - 09:54 AM

/* My implementation of ls */

#include <iostream>

#include <sys/types.h>

#include <dirent.h>



using namespace std;



int LS_implementation(char * directory);

void Print_Failed(char ** failed);



int main(int argc, char ** argv) {

	int i = 1;

	int j = 0;

	char ** fail_list = (char**)calloc(sizeof(char),  30);

	while (argv[i] != NULL) {

		if (LS_implementation(argv[i]) == -1) {

			fail_list[j] = argv[i];

			j++;

		}

		i++;

		cout << endl;

	}

	Print_Failed(fail_list);

        free (fail_list);

	return 0;

}

int LS_implementation(char * directory) {

	DIR * opened_dir;

	struct dirent * directory_structure;

	

	opened_dir = opendir(directory);

	if (opened_dir == NULL) {

		return -1;

	}

	

	cout << "Directory: " << directory << endl;

	

	while (1) {

		directory_structure = readdir(opened_dir);

		if (directory_structure == NULL) {

			closedir(opened_dir);

			return 0;

		}

		cout << directory_structure->d_name << endl;

	}

	

	

	return 0;

}



void Print_Failed(char ** failed) {

	while (*failed != NULL && failed != NULL) {

		cout << "Failed: " << *failed << endl;

		failed++;

	}

}




  • 1


#384696 Math error

Posted by MeTh0Dz on 22 September 2008 - 07:52 PM

This dude was talking ish to me?

lol...
  • 1


#383821 When did you start Writing html?

Posted by MeTh0Dz on 20 September 2008 - 08:52 AM

Dreamweaver does offer a lot of features. But, 99.999999% of the time, when I've seen it used, it has been done so by people who can't code and want to put together web pages. So they just use clicking and dragging.

Hence, why I compared it to VB.
  • 1


#379752 Basic C Help -- Currency Converter

Posted by MeTh0Dz on 07 September 2008 - 10:14 AM

Okay I coded it for you. You will more than likely notice that I did away with the table, and that was because I didn't feel like doing the formatting stuff for it. If you still want to do it like that you can do it, it will probably take you like 10 minutes.

Also, I got lazy in one part and just used exit(0) because I didn't feel like using another flag. Once again if you don't like that, you can just change it. You could also probably write a function to be used in my switch statement in case 2, it would make the code shorter and more structured. But, that's on you. Mmm, I think the code should be good to go, but if you have any problems with it then just post them here.

Oh I also gave the option of changing the conversion factors once the program has ensued.

Lol, **** I just realized that the exit(0) s create a memory leak, I'll work on it later if I feel like it.
Enjoy.

#include <iostream>

using namespace std;

struct Conversion_Factors {
       float USD;
       float GBP;
       float CAD;
       float EUR;
       float AUD;
       float CYN;
};

int Set_Factors(Conversion_Factors * c_f);
void Convert_And_Display(int amount, Conversion_Factors * c_f);
float Get_Correct_Format(float int_amount);

int main() {
    int dead = 0;
    int input = 0;
    Conversion_Factors * conv_f = (Conversion_Factors*)calloc(sizeof(conv_f), 1);
    if (conv_f == NULL) {
       cout << "Failed to allocate memory!\nBYE!\n";
       cin >> dead;
       return 0;
    }
    if (Set_Factors(conv_f) == -1) {
       cout << "BYE!\n";
       cin >> dead;
       free(conv_f);
       return 0;
    }
    
    cout << "Enter the amount to convert in USD: ";
    cin >> input;
    
    Convert_And_Display(input, conv_f);
    cin >> dead;
    free (conv_f);
    return 0;
}

int Set_Factors(Conversion_Factors * c_f) {
     int choice = 0;
     float conv_entry = 0;
     cout << "Enter 1 to use the standard conversion factors, and 2 to set your own.\n>";
     cin >> choice;
     
     switch (choice) {
            case 1: {
                 c_f -> USD = 1;
                 c_f -> GBP = .5653;
                 c_f -> CAD = 1.0637;
                 c_f -> EUR = 0.7006;
                 c_f -> AUD = 1.2335;
                 c_f -> CYN = 6.8400;
                 break;
            }
            case 2: {
                 cout << "USD = ";
                 cin >> conv_entry;
                 c_f -> USD = conv_entry;
                 conv_entry = 0;
                 
                 cout << "GBP = ";
                 cin >> conv_entry;
                 c_f -> GBP = conv_entry;
                 conv_entry = 0;
                 
                 cout << "CAD = ";
                 cin >> conv_entry;
                 c_f -> CAD = conv_entry;
                 conv_entry = 0;
                 
                 cout << "EUR = ";
                 cin >> conv_entry;
                 c_f -> EUR = conv_entry;
                 conv_entry = 0;
                 
                 cout << "AUD = ";
                 cin >> conv_entry;
                 c_f -> AUD = conv_entry;
                 conv_entry = 0;
                 
                 cout << "SYN = ";
                 cin >> conv_entry;
                 c_f -> CYN = conv_entry;
                 conv_entry = 0;
                 
                 break;
            }
            default: {
                     cout << "Your answer sucked!\n";
                     return -1;
            }
     }
     cout << "Thank you!\n";
     return 0;
}

void Convert_And_Display(int amount, Conversion_Factors * c_f) {
     cout << endl << endl;
     
     
     float USD_amount = (amount * c_f->USD);
     USD_amount = Get_Correct_Format(USD_amount);
     float GBP_amount = (amount * c_f->GBP);
     GBP_amount = Get_Correct_Format(GBP_amount);
     float CAD_amount = (amount * c_f->CAD);
     CAD_amount = Get_Correct_Format(CAD_amount);
     float EUR_amount = (amount * c_f->EUR);
     EUR_amount = Get_Correct_Format(EUR_amount);
     float AUD_amount = (amount * c_f->AUD);
     AUD_amount = Get_Correct_Format(AUD_amount);
     float CYN_amount = (amount * c_f->CYN);
     CYN_amount = Get_Correct_Format(CYN_amount);
     
    
     cout << "USD conversion: " << USD_amount << endl;
     cout << "GBP conversion: " << GBP_amount << endl;
     cout << "CAD conversion: " << CAD_amount << endl;
     cout << "EUR conversion: " << EUR_amount << endl;
     cout << "AUD conversion: " << AUD_amount << endl;
     cout << "CYN conversion: " << CYN_amount << endl;
     return;
}
float Get_Correct_Format(float int_amount) {
      float new_amount;
      int dead = 0;
      int i = 0;
      int str_l = 0;
      char * stand_in = (char*)calloc(sizeof(char), 20);
      if (stand_in == NULL) {
        cout << "Memory not allocated!\nBYE!\n";
        cin >> dead;
        exit(0);
      }
      char * new_stand_in = (char*)calloc(sizeof(char), 20);
      if (new_stand_in == NULL) {
        cout << "Memory not allocated!\nBYE!\n";
        cin >> dead;
        free(stand_in);
        exit(0);
      }
      sprintf(stand_in, "%f", int_amount);
      str_l = strlen(stand_in);
      for (i = 0; i < str_l; i++) {
          new_stand_in[i] = stand_in[i];
          if (stand_in[i] == '.') {
             new_stand_in[i + 1] = stand_in[i + 1];
             new_stand_in[i + 2] = stand_in[i + 2];
             break;
          }
      }

      sscanf(new_stand_in, "%f", &new_amount);
      free (stand_in);
      free (new_stand_in);
      return new_amount;
}

  • 0


#376649 What's your favorite GUI toolkit?

Posted by MeTh0Dz on 25 August 2008 - 10:43 AM

Using any type of WYSIWYG or form editor or click and drag program is not coding to me.
  • 1


#373983 Bracket Hax - Esolang

Posted by MeTh0Dz on 15 August 2008 - 11:08 PM

TITLE
Bracket Hax - Esoteric Programming Language


CHANGE LOG


***** August 16, 2008 *****
First release of the Bracket Hax Interpreter, the release is called V .1 .

Known issues
- Lack of error checking.
- If a '#' symbol is missing the interpreter will just run indefinitely.
- If a back-end grouping symbol is not separated by a space from a set of
characters preceded by a '&' symbol, the interpreter will run through
and not stop.
- A loop that never evaluates to false, will make the interpreter run
indefinetly.
- Known bug with multiple while loops, fix in next version
- Also writing a getch() function to eliminate the conio.h library, full cross platform then.

LANGUAGE: C++

TESTED SYSTEMS: Windows XP

LICESNSE: Open Source, see guidelines in the attachment.

PRICE: Free SON


Example Code
Fibonacci's Sequence
# (0 + 0 = !f 0 + 1 = !g) #
# ($RESD $DISP 0 + !f = !f ~ 0 + !g = !g ~) #
#{[^ !f < 200] $RESD $DISP !f + !g = !f ~ !f + !g = !g ~} #


Example Code
Print 1 through 10
#(0 + 0 = !r) #
#[{^ !r < 10} $RESD $DISP !r + 1 = !r ~] #


Contact me, MeTh0Dz, at MeTh0Dz_@hotmail.com.

Attached Files


  • 1


#373463 More Visible Sourecode Section

Posted by MeTh0Dz on 12 August 2008 - 07:50 AM

After being a member of Codecall for some odd months, one thing I would like to see is a more visible sourcecode section in which the members of Codecall can post the finished projects that they have been working on.

Comments?
  • 2




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download