Thread: programmin woes

  1. #16
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    memoryscore = 100 * (memorycount / 20);
    try this way
    Code:
    memoryscore = (100 * memorycount )/ 20;
    Kurt

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    OK, so I take it you want a 20 element array?
    Code:
        int numberarray[19];
    This one holds 19 elements.

    You then fill the array indexes 1..20:
    Code:
        numberarrayplace = 1;
        do {
            numberarray[numberarrayplace] = rand() % 99 + 1;
            cout << numberarray[numberarrayplace] << " \n";
            numberarrayplace = numberarrayplace + 1;
        } while (numberarrayplace < 21);
    When you only have 0..18...

    That loop, by the way, should really be done as a for-loop. Using do - while is completely meaningless. And if you insist on using this loop-form, at least write numberarrayplace++ to add one to your current position.

    Code:
        numberrecalamount = 1;
        memorycount = 0;
    
        do {
            cin >> numberrecal;
            exitcheckloop = 0;
            do {
                if (numberarrayplace > 19) {
                    cout << "Incorrect! \n";
                    numberrecalamount = numberrecalamount + 1;
                    numberarrayplace = 0;
                    exitcheckloop = 1;
                }
                else if (numberarray[numberarrayplace] == numberrecal) {
                    memorycount = memorycount + 1;
                    cout << "Correct! \n";
                    numberarrayplace = 0;
                    numberrecalamount = numberrecalamount + 1;               
                    exitcheckloop = 1;
                     }
                else {
                    numberarrayplace = numberarrayplace + 1;
    
                }
            } while (exitcheckloop == 0);
        } while (numberrecalamount < 20);
    Now you check the elements from 1..19.

    And again, it would be much clearer with a for-loop (using break to exit the loop), and at least using "variable++" where you increment something.

    Code:
    memorycount = 20;
    memoryscore = 100 * (memorycount / 20);
    You are not going to get much other than 100 out of this, are you?

    But more importantly, if memorycount is not 20, then you'll always get zero, becuase x / y in integer math becomes zero if abs(x) < abs(y). Perhaps you would prefer to multiply memorycount by 100 first, then divide by the number of questions. That way, you get a "percentage number".

    Edit: Kurt beat me to the last one.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Sep 2007
    Posts
    26
    Horray it works.

    Thanks for all your help guys !!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. struct constructor woes
    By Mr_Jack in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2004, 03:36 PM
  2. NASA Woes!
    By DISGUISED in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-22-2004, 09:59 PM
  3. Function calling woes
    By RedZippo in forum C Programming
    Replies: 6
    Last Post: 01-09-2004, 12:39 AM
  4. Dll woes
    By Abiotic in forum Windows Programming
    Replies: 3
    Last Post: 11-09-2003, 11:32 AM
  5. Programmin with the MFC
    By omeydhomey in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2003, 08:14 AM