Jump to content
  • Advertisement

Sid_TheBeginner

Member
  • Content Count

    35
  • Joined

  • Last visited

Everything posted by Sid_TheBeginner

  1. Sid_TheBeginner

    i need suggestions can you help me?

    This Guy gives the perfect guide to becoming a professional game programmer or a hobbyist. Watch all the 3 parts: --Sid
  2. Sid_TheBeginner

    Binary Search Help Repost.

    [color=#000000][font=verdana, arial, helvetica, sans-serif]I've got the logic right and the algo seems to work fine. Now, that's epic for me But..[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]I want to add 2 more features to this code:[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]1) Exit on pressing 'x'. For now I'm using -1 to exit.[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]2) Print a message "Element not found" when an element not present in the array is searched for. Yeah, I'm not able to figure that out :|[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]Well, Here goes my code:[/font] [font=verdana, arial, helvetica, sans-serif][color=#000000][/font] #include<iostream> using namespace std; int BinSearch(int data[], int numElements, int searchKey); // Prototype int main() { int data[] = {1, 4, 5, 6, 9, 14, 21, 23, 28, 31, 35, 42, 46, 50, 53, 57, 62, 63, 65, 74, 79, 89, 95}; int numElements = 23; // Size of the Array is 23!!! int searchKey; int found; for(int i = 0; i < numElements; i++) cout << data << ", "; cout << endl; for(;;) { cout << "Enter search key: (-1 to exit) "; // I want to quit when I press 'x'. Please let me know. cin >> searchKey; if(searchKey == -1) { cout << "Exiting\n"; break; } found = BinSearch(data, numElements,searchKey); cout << searchKey << " is in position " << found << endl; } } int BinSearch(int data[], int numElements, int searchKey) { int position, mid; int beg = 0; int end = numElements; // Algorithm Begins. for(int i = beg; i <= end;) { mid = (beg+end)/2; if(data[mid] == searchKey) { return mid; } else if(data[mid] > searchKey) { end = mid - 1; } else if(data[mid] < searchKey) { beg = mid + 1; } } } [font=verdana, arial, helvetica, sans-serif][color=#000000][/font] Thanks, --Sid
  3. Sid_TheBeginner

    Looking for a friend / tutor.

    Google Game Institute. You gotta pay them just 99$ for the whole stuff. Some discount going on I guess. They're not frauds. Piratebaybay told me so, it also told me their content is just awesome ;) But you pay them 99$ and you'll get full support for your course. Its perfect for beginners. As its right from the ground up and will take you flying. --Sid
  4. Sid_TheBeginner

    Binary Search Help Repost.

    Sorry... Actually I didn't know there was a problem there.
  5. Sid_TheBeginner

    Binary Search Help Repost.

    [color=#000000][font=verdana, arial, helvetica, sans-serif]I've got the logic right and the algo seems to work fine. Now, that's epic for me But..[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]I want to add 2 more features to this code:[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]1) Exit on pressing 'x'. For now I'm using -1 to exit.[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]2) Print a message "Element not found" when an element not present in the array is searched for. Yeah, I'm not able to figure that out :|[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif]Well, Here goes my code:[/font] [color=#000000][font=verdana, arial, helvetica, sans-serif][/font] #include<iostream> using namespace std; int BinSearch(int data[], int numElements, int searchKey); // Prototype int main() { int data[] = {1, 4, 5, 6, 9, 14, 21, 23, 28, 31, 35, 42, 46, 50, 53, 57, 62, 63, 65, 74, 79, 89, 95}; int numElements = 23; // Size of the Array is 23!!! int searchKey; int found; for(int i = 0; i < numElements; i++) cout << data << ", "; cout << endl; for(;;) { cout << "Enter search key: (-1 to exit) "; // I want to quit when I press 'x'. Please let me know. cin >> searchKey; if(searchKey == -1) { cout << "Exiting\n"; break; } found = BinSearch(data, numElements,searchKey); cout << searchKey << " is in position " << found << endl; } } int BinSearch(int data[], int numElements, int searchKey) { int position, mid; int beg = 0; int end = numElements; // Algorithm Begins. for(int i = beg; i <= end;) { mid = (beg+end)/2; if(data[mid] == searchKey) { return mid; } else if(data[mid] > searchKey) { end = mid - 1; } else if(data[mid] < searchKey) { beg = mid + 1; } } } Thanks, --Sid
  6. Sid_TheBeginner

    Binary Search Help Repost.

    I replaced for with while that helped. Thank You. @ szecs you're not the only one who didn't notice it . In another forum also, someone has just now figured it. THank you'll --Sid
  7. Sid_TheBeginner

    Binary Search Help Repost.

    I wan't to print "Not found" if a value which isn't found in the array is entered by the user.
  8. Sid_TheBeginner

    Binary Search Help Repost.

  9. Sid_TheBeginner

    Binary Search Help Repost.

    Thanks for replying. Did You mean this: #include<iostream> using namespace std; int BinSearch(int data[], int numElements, int searchKey); // Prototype int main() { int data[] = {1, 4, 5, 6, 9, 14, 21, 23, 28, 31, 35, 42, 46, 50, 53, 57, 62, 63, 65, 74, 79, 89, 95}; int numElements = 23; // Size of the Array is 23!!! int searchKey; int found; for(int i = 0; i < numElements; i++) cout << data << ", "; cout << endl; for(;;) { cout << "Enter search key: (-1 to exit) "; // I want to quit when I press 'x'. Please let me know. cin >> searchKey; if(searchKey == -1) { cout << "Exiting\n"; break; } found = BinSearch(data, numElements,searchKey); if(found == -1) cout << "Not Found!\n"; else cout << searchKey << " is in position " << found << endl; } } int BinSearch(int data[], int numElements, int searchKey) { int mid; int beg = 0; int end = numElements; // Algorithm Begins. for(int i = beg; i <= end;) { mid = (beg+end)/2; if(data[mid] == searchKey) return mid; else if(data[mid] > searchKey) end = mid - 1; else if(data[mid] < searchKey) beg = mid + 1; } return -1; } Not working.
  10. Sid_TheBeginner

    Binary Search Help Repost.

    Thanks! No more warnings now. I'm returning -1 outside the for loop in the BinSearch function But how do I print a message like "Element not found" using that return value -1 ?? Your English doesn't suck, I'm pure rookie
  11. Sid_TheBeginner

    Binary Search Help Repost.

    @szecs Hey, thanks for your replyl! Do you mean this: #include<iostream> using namespace std; int BinSearch(int data[], int numElements, int searchKey); // Prototype int main() { int data[] = {1, 4, 5, 6, 9, 14, 21, 23, 28, 31, 35, 42, 46, 50, 53, 57, 62, 63, 65, 74, 79, 89, 95}; int numElements = 23; // Size of the Array is 23!!! int searchKey; int found; for(int i = 0; i < numElements; i++) cout << data << ", "; cout << endl; for(;;) { cout << "Enter search key: (-1 to exit) "; // I want to quit when I press 'x'. Please let me know. cin >> searchKey; if(searchKey == -1) { cout << "Exiting\n"; break; } found = BinSearch(data, numElements,searchKey); if(found == -1) cout << searchKey << " not found\n"; cout << searchKey << " is in position " << found << endl; } } int BinSearch(int data[], int numElements, int searchKey) { int mid; int beg = 0; int end = numElements; bool not_found = 1; // Algorithm Begins. for(int i = beg; i <= end;) { mid = (beg+end)/2; if(data[mid] == searchKey) return mid; else if(data[mid] > searchKey) end = mid - 1; else if(data[mid] < searchKey) beg = mid + 1; else return -1; } } This doesn't seem to work. Sorry, I didn't completely understand what you meant... And Yea, the compiler's telling me this: warning C4715: 'BinSearch' : not all control paths return a value
  12. Sid_TheBeginner

    Binary Search Help Repost.

    Damn! What was that?? Lol. I've reposted it
  13. Which Languages are used for specifically Multiplayer Programming in Games? I've basic knowledge of Computer Networks and would also be having Advanced Computer Networks soon and also "High Speed Network Architecture and Protocols, Neural Networks later" in my college..Will these subjects help me in learning Multiplayer Programming? I'm interested in Networking altogether. So how does Networking come in games and which languages are used? I'm new to programming and have begun with C++. Sorry for not narrowing my question. In short please enlighten me about multiplayer programming in games... Thanks, --Sid
  14. Sid_TheBeginner

    Programming Language for Multiplayer Programming

    Thanks for all the wonderful replies. I think I'll stick with C++
  15. Sid_TheBeginner

    Programming Language for Multiplayer Programming

    Hey thanks for your reply! I'm currently learning C++ The learning curve seems steep. But I'm just pushing myself When a large program runs I'm motivated else a bit restless
  16. Sid_TheBeginner

    Breaking out of an infinite loop

    Suppose i have a code like this: for(;;) { int value; cout << "Enter value(q to quit): "; cin >> value; } I want to quit when q is entered. How do i do it? I'm yet not introduced to the ctype library in the book I'm following. So which are the other methods to do so? Thanks, --Sid
  17. Sid_TheBeginner

    Breaking out of an infinite loop

    I've given up this program for now. I curse my speed. I'm just rushing I'm gonna come back to it tomorrow and try to reconstruct the whole program. On some other forum I'm told that this is not even binary search Thanks a lot for the help.
  18. Sid_TheBeginner

    Breaking out of an infinite loop

    Oops! sorry for the confusion i'll post my code: Its the Binary Search Algo: #include<iostream> #include<ctype.h> using namespace std; int main() { int arr[] = {1, 4, 5, 6, 9, 14, 21, 23, 28, 31, 35, 42, 46, 50, 53, 57, 62, 63, 65, 74, 79, 89, 95}; int value; for(int i = 0; i < 23; i++) cout << arr << " "; cout << endl; while(1) { cout << "Enter seach value(-1 to exit): "; cin >> value; if(value == -1) { cout << "Exiting..\n"; break; } int beg = 0; int end = 23; for(beg = 0; beg < 23; beg++) { int middle = (beg+end)/2; if(value == arr[middle]) { cout << "Its at location " << middle << endl; break; } else if(value > arr[middle]) end = middle + 1; else if(value < arr[middle]) end = middle - 1; else cout << "Element Not found\n"; } } } So basically, I want to quit when q is entered. For now I'm using -1 as suggested by japro. An exercise demands 'q' and so I decided to post.
  19. Sid_TheBeginner

    Breaking out of an infinite loop

    Sorry I didn't understand. Can you please post a small snippet of code? -1 works fine. But I just wanted to know how to quit using a character such as 'q'.
  20. Sid_TheBeginner

    Breaking out of an infinite loop

    That's just causing an infinite loop at the command prompt.
  21. Sid_TheBeginner

    New to programming (duh) had some questions...

    I would recommend these set of videos http://xoax.net/cpp/crs/console/index.php. I've already started teaching myself C++ from a book so I don't want to jump to these videos. But when I have any algorithm confusions I do check out this website. If you haven't started then this is a great place to start I believe. But once you start following these videos don't "jump" somewhere else. Post your questions here. Cheers, --Sid
  22. I prefer Visual C++ 2010 its really great according to me.
  23. Sid_TheBeginner

    Please simplify my code.

    I've been interested in game programming recently. So I've started learning C++ I'm a total beginner. Please review my code and also help me to improve it. I want a slot machine with: 1000$ to start with. It's seems to be working. Please help me to make it more simpler. // A Slotting Machine implementation #include<iostream> #include<ctime> #include<cstdlib> using namespace std; int Random(int low, int high); int main() { int low = 2; // Random number range. int high = 7; // Random number range. int r0, r1, r2; int money = 1000; // Initial money to start with. int reply = 0; char exit; int bet; char restart; char cont; srand( time (0) ); // Default Random Number function call. cout << "Players chips: $1000"<< endl; while(true) { cout << "1) Play slot. 2) Exit. "; cin >> reply; if(reply == 1) { while(1) { while(true) { cout << "Enter your bet: "; cin >> bet; if(bet > 0 && bet <= money) break; else cout << "Please enter a valid bet.\n"; } r0 = Random(low, high); // Function call cout << r0 <<" "; r1 = Random(low, high); // Function call cout << r1 << " "; r2 = Random(low, high); // Function call cout << r2 << endl; if (r0 == r1 == r2 == 7) // Machine's number sequence. { money = (10 * bet); cout << "Lucky Bucky!\n"; cout << "Players chips: $" << money << endl; } if((r0 == r1 == r2) && (r0 != 7 && r1 != 7 && r2 != 7)) // Machine's number sequence. { money = (5 * bet); cout << "Not Bad!\n"; cout << "Players chips: $" << money << endl; } if(r0 == r1 || r1 == r2 || r0 == r2) // Machine's number sequence. { money = (3 * bet); cout << "Go Happy!\n"; cout << "Players chips: $" << money << endl; } else { cout << "You Lose!\n"; money -= bet; // Get Previous amount back. cout << "Your Money: " << money << endl; if(money == 0) { cout << "You just got flushed!\n"; cout << "Exiting...\n"; break; } } cout << "1) Play slot. 2) Exit. "; cin >> cont; if(cont == '1') continue; else cout << "Exiting\n"; break; } } else if (reply == 2) cout << "Exiting\n"; break; } } int Random(int low, int high) { int r0 = low + rand() % ((high + 1) - low); return r0; int r1 = low + rand() % ((high + 1) - low); return r1; int r2 = low + rand() % ((high + 1) - low); return r2; }
  24. Sid_TheBeginner

    Newbie

    Yeah, I watched all the 3 parts before a few days and that's why decided to start learning C++ because I've no clue about what is what and so I decided to take this guy's words by heart.
  25. Sid_TheBeginner

    Newbie

    Check out this video on youtube: [media][/media] Watch all the 3 short parts. This guy truly seems to know his stuff.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!