snakey Posted March 5, 2008 Author Share Posted March 5, 2008 Yer i didnt get it Quote Link to comment Share on other sites More sharing options...
kaizen_0 Posted March 5, 2008 Share Posted March 5, 2008 u have to make a random generator (not only numbers) where u can enter the choices. and make it with errors that the compiler cant catch and get people to find them. Quote Link to comment Share on other sites More sharing options...
K1u Posted March 5, 2008 Share Posted March 5, 2008 u have to make a random generator (not only numbers) where u can enter the choices. and make it with errors that the compiler cant catch and get people to find them. I made this a long ass time ago. http://www.k0h.org/portal/index.php?option...8&Itemid=47 Do not include it in the competition though. Quote Link to comment Share on other sites More sharing options...
snakey Posted March 6, 2008 Author Share Posted March 6, 2008 its spose to crash Quote Link to comment Share on other sites More sharing options...
easy_code Posted March 13, 2008 Share Posted March 13, 2008 is this the code that you want? only runtime errors and not syntax errors #include <iostream> #include <ctime> using namespace std; char get_Char(); int get_Int(); template <class Type> bool compare(Type,Type); int main(){     int myNum, randNum;     char myChar, randChar;     char again;         cout<<" Welcome to the Awesome Game n";             do{         cout<<"*******************************n";         myChar = get_Char();         myNum = get_Int();                 randChar = rand()%4;         randNum = rand()%3;                 if(compare<int>(myNum, randNum) && compare<char>(myChar, randChar))             cout<<"You Winn";         else             cout<<"You Loosen";         cout << "do you want to play again(y/n)? ";         cin >> again;     }while(again = 'y');     cout<<"*******************************n"         <<"Thanks for Playingn";     return 0; } char get_Char(){     char temp;     cout<<"enter a character(a-d): ";     cin>>temp;     return temp; } int get_Int(){     int temp;     cout<<"enter an integer(1-3): ";     cin>>temp;     return temp; } template <class Type> bool compare(Type a,Type b){     if(a=b)         return true;     else         return false; } edited after sablefoxx's comment #55 and my comment #56 Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted March 13, 2008 Share Posted March 13, 2008 Compiler catches some of it: ./guess.cpp: In function ‘int main()’: ./guess.cpp:33: warning: suggest parentheses around assignment used as truth value ./guess.cpp: In function ‘bool compare(Type, Type) [with Type = int]’: ./guess.cpp:25: instantiated from here ./guess.cpp:54: warning: suggest parentheses around assignment used as truth value ./guess.cpp: In function ‘bool compare(Type, Type) [with Type = char]’: ./guess.cpp:25: instantiated from here ./guess.cpp:54: warning: suggest parentheses around assignment used as truth value But it does compile, and the program does not work (just the way its supposed to?) Quote Link to comment Share on other sites More sharing options...
easy_code Posted March 13, 2008 Share Posted March 13, 2008 sablefoxx what compiler are you using? I'm using Microsoft Visual Studio 2005 and I don't see any warnings or errors this is not one of the errors but should fix some of the strict warnings your compiler is giving you try replacing line 25: if(compare(myNum, randNum) && compare(myChar, randChar)) with: if(compare<int>(myNum, randNum) && compare<char>(myChar, randChar)) Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted March 14, 2008 Share Posted March 14, 2008 i am using g++, im in Ubuntu 7.10Â :) Quote Link to comment Share on other sites More sharing options...
easy_code Posted March 14, 2008 Share Posted March 14, 2008 Your compiler did find some of the errors, and i don't think i can hide them from you compiler. Try fixing the errors and look for the rest of the errors. Also post as you fix errors. Quote Link to comment Share on other sites More sharing options...
snakey Posted March 15, 2008 Author Share Posted March 15, 2008 so is it Valid? Quote Link to comment Share on other sites More sharing options...
kaizen_0 Posted March 16, 2008 Share Posted March 16, 2008 its good. easy_code did everyone find the all the errors? please post all the errors you have. when u do then, i guess since u where the only one to enter u win and u get to post the new challenge. Good Job easy_code. Quote Link to comment Share on other sites More sharing options...
easy_code Posted March 16, 2008 Share Posted March 16, 2008 sablefoxx's found some of the errors on lines 33,and 54 33: }while(again = 'y'); 53: if(a=b)  //it waws actually on 53 someone could post what these errors are there are still 2 more errors. i could post the errors you want. Quote Link to comment Share on other sites More sharing options...
snakey Posted March 16, 2008 Author Share Posted March 16, 2008 How bout a new challenge? Quote Link to comment Share on other sites More sharing options...
TheWarden Posted March 16, 2008 Share Posted March 16, 2008 randChar = rand()%4; Won't work unless the user somehow enters a control character. In order for this line to work, it would have to move the random character into the range of printable characters (eg: randChar += 'a'; ). Quote Link to comment Share on other sites More sharing options...
easy_code Posted March 17, 2008 Share Posted March 17, 2008 here are the solutions: 1 and 2: line #33 & 53 }while(again = 'y');  if(a=b) there is a logical error. the = will alaways return true. this is because the compiler sees it as an assignment. the = should be == to make it a comparison. 3: line #22 randChar = rand()%4; the range of comparible characters is not a,b,c instead it has a range of: null, ?, ?, ? to fix this add 'a' or 97 to get it in the range of a-d 4: line #2 #include <ctime> This is not the error but a hint. You can write a line that initializes the random number based on the system time. srand(time(0)); This allows you to be able to run the app without having it choose the same random number every time. Congrats to: sablefoxx and TheWarden for finding errors 1, 2, and 3 Here is the Next Challenge: Wrte a Program that 1. an integer is inputed 2. the number is converted to binary 3. output the binary number Bonus: make it also do Octal and/or Hexadecimal Quote Link to comment Share on other sites More sharing options...
jordanbray Posted March 26, 2008 Share Posted March 26, 2008 FIRST POST AT HAK. 5! Code for the challenge IOCCC style. . . #include <stdio.h> #include <stdlib.h> #include <assert.h> void print_str(unsigned char *str) {     printf("%c", *str);     while (*str != str[-1]) {         str++;         printf("%c", *str - (-1)[str]);     } } int main(int argc, char *argv[]) {     char str1[] = { 0x2a, 0x54, 0x7e, 0xa8, 0xd2, 0xfc, 0x26, 0x50, 0x7a,             0xa4, 0xce, 0xf8, 0x22, 0x4c, 0x76, 0xa0, 0xca, 0xf4,             0x1e, 0x48, 0x72, 0x9c, 0xc6, 0xf0, 0x1a, 0x44, 0x6e,             0x98, 0xc2, 0xcc, 0xf6, 0x16, 0x6a, 0xd2, 0x3b, 0xae,             0xce, 0x37, 0xaa, 0xca, 0x39, 0x9b, 0x01, 0x76, 0xe9,             0x4a, 0xbe, 0x23, 0x87, 0xa7, 0x0a, 0x79, 0xdd, 0x42,             0x62, 0xd6, 0x45, 0x65, 0x8f, 0x99, 0xc3, 0xe3, 0x53,             0xc5, 0x2e, 0x9c, 0x10, 0x30, 0x9e, 0x13, 0x80, 0xe2,             0x47, 0xb9, 0x2c, 0x4c, 0xb5, 0x23, 0x43, 0xa5, 0x0e,             0x7c, 0xdd, 0x4f, 0xc8, 0xf6, 0x16, 0x36, 0x60, 0x6a,             0x94, 0xbe, 0xe8, 0x12, 0x3c, 0x66, 0x90, 0xba, 0xe4,             0x0e, 0x38, 0x62, 0x8c, 0xb6, 0xe0, 0x0a, 0x34, 0x5e,             0x88, 0xb2, 0xdc, 0x06, 0x30, 0x5a, 0x84, 0xae, 0xd8,             0x02, 0x2c, 0x36, 0x36 }; /* no, it's not ascii */     char str2[] = { 0x45, 0xb3, 0x27, 0x8c, 0xfe, 0x1e, 0x7f, 0x9f, 0x0d,             0x82, 0xef, 0x51, 0xb6, 0x28, 0x48, 0xbc, 0x2b, 0x4b,             0xad, 0x12, 0x32, 0x95, 0x04, 0x72, 0xe8, 0x4d, 0xbf,             0x33, 0x98, 0xfc, 0x1c, 0x90, 0xff, 0x1f, 0x87, 0xec,             0x64, 0x9e, 0xbe, 0xbe }; // ascii strings are NULL terminated     char str3[] = { 0x54, 0xbc, 0x25, 0x98, 0xb8, 0x21, 0x94, 0xb4, 0x28,             0x90, 0xf5, 0x15, 0x84, 0xf9, 0x6d, 0xdd, 0x52, 0xc6,             0xe6, 0x55, 0xbb, 0xdb, 0x52, 0xb3, 0x2c, 0x4c, 0x7d,             0x87, 0x87 };     char str4[] = { 0x54, 0xbc, 0x25, 0x98, 0xb8, 0x21, 0x94, 0xb4, 0x28,             0x90, 0xf5, 0x15, 0x84, 0xf9, 0x6d, 0xdd, 0x52, 0xc6,             0xe6, 0x55, 0xbb, 0xdb, 0x52, 0xb3, 0x2c, 0x4c, 0x7e,             0x88, 0x88 };     void **p;     print_str(str1);     print_str(str2);     scanf("%d", *((!(*((!(p = malloc(sizeof(int))) ? abort() : p), p) =               malloc(sizeof(int))) ? abort() : p), p));     void *buf;     /* way one */     sprintf((((buf = malloc(42 /* more than the meaning of life */)) == NULL           ? abort() : buf), buf), "%x", 0[0[(int **) p]]);     print_str(str3);     while (*(char *)buf) {         if (*(char *)buf >= 'a')             *(char *)buf -= 'a' - 10;         else             *(char *)buf &= ~'0';         printf("%d", (*(char *)buf & 8) >> 3);         printf("%d", (*(char *)buf & 4) >> 2);         printf("%d", (*(char *)buf & 2) >> 1);         printf("%d", (*(char *)buf & 1));         buf++;     }     printf("n");     /* way two */     print_str(str4);     char i, j;     i = 3 + (j ^= j);     do {         if (!(j % 8)) {             i[0[(char **) p]] = ((i[0[(char **) p]] & 0xf0) >> 4) |                       ((i[0[(char **) p]] & 0x0f) << 4);             i[0[(char **) p]] = ((i[0[(char **) p]] & 0xcc) >> 2) |                       ((i[0[(char **) p]] & 0x33) << 2);             i[0[(char **) p]] = ((i[0[(char **) p]] & 0xaa) >> 1) |                       ((i[0[(char **) p]] & 0x55) << 1);         }         printf("%d", (i[0[(char **) p]] >> j) & 1);     } while ((j = (++j % 8)) || i--);     printf("n");     return 0; } Have fun if you try to decipher it :-P Quote Link to comment Share on other sites More sharing options...
MBP Posted March 28, 2008 Share Posted March 28, 2008 So is it valid. Can we have confirmation's? Quote Link to comment Share on other sites More sharing options...
jordanbray Posted March 29, 2008 Share Posted March 29, 2008 it's definitely valid... output: jordan@jordan-desktop:~$ gcc -Wall -o main01 main01.c main01.c: In function ‘main’: main01.c:42: warning: pointer targets in passing argument 1 of ‘print_str’ differ in signedness main01.c:43: warning: pointer targets in passing argument 1 of ‘print_str’ differ in signedness main01.c:45: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘void *’ main01.c:51: warning: pointer targets in passing argument 1 of ‘print_str’ differ in signedness main01.c:67: warning: pointer targets in passing argument 1 of ‘print_str’ differ in signedness jordan@jordan-desktop:~$ ./main01 ***************************** * This is obfusated code to * * print numbers in binary. * ***************************** Enter a number to be converted to hex: 100 This is the output of way 1 01100100 This is the output of way 2 00000000000000000000000001100100 jordan@jordan-desktop:~$ ./main01 ***************************** * This is obfusated code to * * print numbers in binary. * ***************************** Enter a number to be converted to hex: 64 This is the output of way 1 01000000 This is the output of way 2 00000000000000000000000001000000 jordan@jordan-desktop:~$ ./main01 ***************************** * This is obfusated code to * * print numbers in binary. * ***************************** Enter a number to be converted to hex: 256 This is the output of way 1 000100000000 This is the output of way 2 00000000000000000000000100000000 jordan@jordan-desktop:~$ The compiler complains a bit and it says 'converted to hex' instead of 'converted to binary', but it does the job, twice (one uses printf to get it to hex first and I decided that was cheating, so I solved it a different way too). Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted March 30, 2008 Share Posted March 30, 2008 :-P easy! #include <stdio.h> int main( ){       void bin (int); //function proto       unsigned int i;      printf("nnInput: ");      scanf(" %d", &i); //get input      printf("Bin = ");      bin(i); //send i to get converted      printf("nOct = %o n", i); //octal      printf("Hex = %x n", i); //hex      return 0;}    void bin (int i){  while (i != 0){   printf ("%d",i % 2);   i = i /2;}  return; } Quote Link to comment Share on other sites More sharing options...
MBP Posted March 31, 2008 Share Posted March 31, 2008 He hasn't been on since the 17TH so im going to announce jordanbray the winner YAY post next challenge bud. Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted March 31, 2008 Share Posted March 31, 2008 wtf, why does he win? You cant even read the damn code! Are we trying to make the best bloatware? Im not trying to say mine was better, but we should strive to promote, easy to read, and well written code. just a thought :P , looking forward to next challenge! Quote Link to comment Share on other sites More sharing options...
jordanbray Posted March 31, 2008 Share Posted March 31, 2008 wtf, why does he win? You cant even read the damn code! Are we trying to make the best bloatware? That was the point... Also, I'm pretty sure bloatware is unneeded features/programs. This would be classified as obfuscated code. Hint: Code for the challenge IOCCC style... I was kinda trying to make illegible code... In other news, the next challenge may (should) be deciphering what I wrote... Quote Link to comment Share on other sites More sharing options...
MBP Posted April 1, 2008 Share Posted April 1, 2008 Just make the next challenge :P Quote Link to comment Share on other sites More sharing options...
snakey Posted April 10, 2008 Author Share Posted April 10, 2008 stablefoxx make the next challenge mate jordan has left aswel :P Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted April 11, 2008 Share Posted April 11, 2008 *** Coding Challange April 11-25 2008 *** 1. Must be written in C / C++ / VBS 2. Take in any number of values (can be user defined or read values until EOF) 3. Sort Values, Largest to Smallest 4. Use least chrs possible (white space/comments don't count) 5. Code should be clean and well commented 6. Must print entire array before/after sort 7. You can only use one Print function (you can use as many other functions as you want) ~2 Weeks, Good Luck Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.