Jump to content

PruritusAni

Folding Member
  • Posts

    258
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by PruritusAni

  1. Ugh, I almost forgot my hatred for c-style strings. If you have a choice, always use regular strings as they're a lot more intuitive, and you don't have to worry about buffer overflows and reading the string in properly.

     

    I got this to work in my Visual Studio:

     

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    struct Students {
    int ID;
    char name[80];
    double GPA;
    char email [1000];
    };
    
    int main()
    {
       char choice[256]; // for yes or no
       Students nour = { 9103614, "Nour Eldin Ali", 3.81, "[email protected]" };
       Students adham = { 9103615,"Adham Ayman Zaki", 3.91, "[email protected]" };
       long ID;
    
    
       while(true)
       {
    	cout << "Enter the student's ID " << endl;
    	cin >> ID;
    
    	if ( ID == 9103614 )
    		cout << endl << nour.name << endl << nour.GPA << endl << nour.email << endl << endl;
    	else  if ( ID == 9103615 )
    		cout << endl << adham.name << endl << adham.GPA << endl << nour.email << endl << endl;
    	else 
    		cout << endl << "Incorrect ID" << endl << endl;
    
    	cout << "if you want to do it again , type yes or no " << endl;
    	cin >> choice;
    
    	if ( !strcmp(choice, "yes") )
    		cout << endl << "Lets do it again!" << endl;
    	else if ( !strcmp(choice, "no") )
    		break;
    	else
    	{
    		cout << endl << "invalid choice, program terminates now" << endl;
    		return 0;			
    	}
       }
    
       return 0;
    }

     

    it turns out that gets, or cin.getline(choice, 10) both fail so cin was the only way to make it work. It is very important to note however that if the guy enters smth with more than 9 characters you'll get buffer overflow and are setting your program up for easy hijacking. I made the string large enough that hopefully someone would get bored typing that many characters in, but this won't deter any buffer overflow attacks. Bottom line? don't use c-style strings.

     

    I know there must be a way to make this work with c-style strings, but I just don't know it. Surely there must be some c-style string expert lurking around here laughing at my incompetence.

  2. hmm weird, it never says "it worked"?I think it may have to do with some sort of basic assumption I'm making about c style strings and strings. let's try using strcmp after all. Try to see if this works:

     

     if ( strcmp(choice, "yes") == 0 )
      cout<<"it worked";
    else if ( strcmp(choice, "no") == 0)
      break;
    else
    {
      cout << "invalid choice, program terminates now" << endl;
      return 0;
    }
    

     

    I was told a long time ago, and many times after that by various programming profs to not use goto if I could avoid it at all, and I guess I obeyed. I think there are more elegant ways to do the same things a goto does, especially in objected oriented languages. You could easily use functions and classes along with the trusty while loop to circumvent any sort of goto usage. Some of the modern programming languages go so far as to lack a goto instruction (I know java and python don't have it), so I guess there may be some sort of goto shunning conspiracy that I'm also part of. :biggrin:

  3. It is not really that advanced what I did, just built a bit on top of what you were doing. Feel free to remove things from my code if they're too "fancy".

    Have you tried playing with my code a bit to see if it works? It should do more or less what you want your code to do.

     

    If you're using a for loop with no counter or stopping condition what you really want is the while loop.

    I personally don't care for using goto at all, so I avoid it, as it's easy to mess up things with it.

     

    Hope you get it to work properly.

  4. are there no == or != operators in the cstring class? Are you asking if the choice is not "yes"? There's a ! in there which negates the return value of strcmp in both conditional statments.

     

    perhaps avoiding goto like you would the plague is a good idea after all. Try it with a while loop and a break if the guy says no:

     

    int main ()
    {
    // declare your needed variables and stuff here
    
    // brute force the two students here
    // perhaps expansions of the program would allow for adding of other students and storing them in a data structure
    
    while( true )
    {
    cout << " Enter the student's number" << endl;
    cin >> ID;
    if (ID == smth)
    {
       //display that guy's stuff
    }
    else if (ID == smth else)
    {
       //display this other guy's stuff
    }
    else
      cout << "student with " << ID << " not found" << endl;
    
    cout << " Would you like to do this again?" << endl;
    cin >> choice;
    if (choice == "no" || choice == "No" || choice == "N")
      break;
    else if ( choice != "yes" || choice != "Yes" || choice != "Y")
    {
      cout << "invalid choice, program terminates now" << endl;
      return 0;
    }
    }
    
    return 0;
    }
    

  5. Yeah but..

     

    I don't care that was the coolest thing I found in a while, I expected something stupid. These short midis are awesome (I love midis!!)

     

    didn't it say that one of them (flourish) was used for directx diagnostics? Maybe the others the result of awesome procrastination on the part of a very musically inclined programmer. Or we could get crazy with the theories right here and claim they hold carefully encrypted code for when the global network of Windows becomes self aware. *grabs tinfoil hat*

     

    Nevertheless, it is indeed an awesome find, and I commend you for it, as I too love a good midi. :thumbsup:

  6. You've got me... maybe the folders were added :dunno:

     

    I think it got us ... :biggrin:

     

    So if other folders do indeed see the little box (need to eliminate the possibility of me just being weird, as is often the case), a good way to get rid of line is to sacrifice the stars, and get the ribbon. :foldon:

  7. Odd. Maybe regular members just don't get one of those boxes? I don't remember it being there before the update, but my memory is not reliable unless smells or numbers are involved. You both seem to be folding, maybe joining the Folding members group will give you access to the box? Not to mention you get a fancy DNA strand to go with it (You lose the stars though). Can anyone confirm my speculations?

  8. do you actually need both 8pinners connected? I seem to recall a lot of similar high end boards needing the extra 8pin connection only for ridiculous overclocks. It should work just fine for a regular overclock with just one 8pin guy in there.

     

    EDIT: You might also want to take a look at this thread. There may be a way for you to get a second 8 pin cable.

  9. I thought that was optional, if you don't like it you can just not check the "show edited by" thing. Or do you want it to show as a way to timestamp edits, but would like it to be smaller?

     

    EDIT: I just edited it and checked the box, to annoy you. :P

    • Like 1
  10. I do enjoy all of the listed options, but most of the time it's nearly therapeutic to go on a slaughtering spree without the legal ramifications. It's also a good way to completely reset the mind after prolonged abuse via complicated and attention demanding tasks. There's only so many hours one can spend focused on a certain task, so when a lot of these hours have to be logged in a few days, small breaks for FPS can work wonders.

  11. Woo! I won me some post apocalyptic Russian madness! I'm very excited as I hear it's a fantastic game. Congratulations to the other winners as well, especially to wevsspot. Many thanks go out to Bosco and MSI for putting this contest together. :cheers:

    • Like 1
  12. try out "foof" too i just found it and i'm givin it a shot....

     

    I just gave it a shot, but it still doesn't work on hulu, as one can see here.

     

    EDIT: and it also breaks adultswimfix just as bad as ad block plus. They ought to include a subscription filter to abp just for video streaming websites.

  13. I tried putting it in the signature, and it didn't work, I may have been slightly retarded in the process ... let me see if I can replicate the issue

     

    EDIT: There it is! My signature now has a broken HTML folding image going on under the working BB code one.

     

    EDIT2: I re-read your post, and realize why the HTML alternative isn't working .... It's because it is meant to be used on a website or blog .... So I was doing something retarded in the process all along. :pfp:

×
×
  • Create New...