nullptr 167 Occasional Poster

You could also handle invalid input like this:

    unsigned short int x;
    bool flag = false;
    cout << "Enter an integer that I will reverse i.e. 301 --> 103" << endl;

    while (!flag)
    {
        cin >> x;
        if (cin.fail() )
        {
            // clear error flags and flush input
            cin.clear();
            cin.ignore(90, '\n');
            cout << "Invalid input, enter another integer" << endl;
            continue;
        }

        flag = true;
    }
    cout << reverse_num(x);
    cout << endl;
nullptr 167 Occasional Poster

You're variables are being filled in the scope of main(), so once you call output() those variables are no longer in scope.

The 'dirty' solution would be to declare the variables as global variables. A cleaner way would be to define a struct to hold the variables, fill the struct and pass either the struct instance or pointer to the output function.

nullptr 167 Occasional Poster

Something like this?

struct person {
        string first;
        string last;
        string addr;
        string phone;
};

int main ()
{
    vector<person> pvec;
    person tp;

    tp.first = "Rhino";
    tp.last = "Neil";
    tp.addr = "22 Acacia Avenue";
    tp.phone = "5554646";

    pvec.push_back(tp);

    tp.first = "Orson";
    tp.last = "Cart";
    tp.addr = "Some Place, Unknown";
    tp.phone = "5551212";

    pvec.push_back(tp);

    for (person p : pvec)
        cout << p.first << " " << p.last << " - " << p.addr << " - " << p.phone << endl;

    cout << endl << "press Enter to exit...";

    cin.get();

    return 0;
}
nullptr 167 Occasional Poster

The second pow function has no exponent.

I thought this at first, but if you look closer you'll realise that it does.

On line 42. a = sqrt(x);
What is the purpose of a and where should it be used? (line 43?)

NathanOliver commented: Nice catch. +10
nullptr 167 Occasional Poster

This should work for you. Note that you have only 3 choices so there's no need for
else if (compchoice == 2). As it's the only remaining condition, you can simply have else

int main()
{
    srand ( time(NULL) );
    int choice;
    int compchoice;
    int winCount = 0;

    //Creating the interface
    cout << "Welcome to the Rock, Paper, Scissors game." << endl;

    do
    {
        cout << " 1 = Rock, 2 = Paper, 3 = Scissor, 4 = Exit Program" << endl;

        compchoice = rand() % 3;
        cin >> choice;
        // flush input stream
        cin.ignore(90, '\n');

        if (choice == 1) 
        {
            if (compchoice == 0)
                cout << "It's a tie!\n\n\n\n";
            else if (compchoice == 1)
                cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
            else //if (compchoice == 2)
            {
                cout << "Rock beats scissors! You win!\n\n\n\n";
                winCount += 1;
            }
        }

        if (choice == 2)
        {
            if (compchoice == 0)
                cout << "It's a tie!\n\n\n\n";
            else if (compchoice == 1)
            {
                cout << "Paper beats rock! You win!\n\n\n\n";
                winCount += 1;
            }
            else //if (compchoice == 2)
                cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
        }

        if (choice == 3)
        {
            if (compchoice == 0)
                cout << "It's a tie!\n\n\n\n";
            else if (compchoice == 1)
            {
                cout << "Scissors beat paper! You win!\n\n\n\n";
                winCount += 1;
            }
            else //if (compchoice == 2)
                cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
        }

        if (choice == 4)
        {
            return 0;
        }

    } while (winCount < 3);

    cout << "You won three …
nullptr 167 Occasional Poster

Edit:

    while (count < num) {
        sum += a[count];
        ++count;
        average=sum/num; // 
    }

That should actually work, though it's not optimal because average is being calculated every time you loop through the array, though the result only becomes valid on the final loop.

nullptr 167 Occasional Poster

The major reason that your tableAverage function fails is because the average is being calculated inside the loop that iterates through the array.

    while (count < num) {
        sum += a[count];
        ++count;
        average=sum/num; // this should not be inside the loop
    }

You also declare float average when infact you want a double. There's really no reason to declare a variable for average either. Just follow deceptikon's previous advice for the tableAverage.

int tableMatchingElements(double a[], int num, double average)
{
    int ct = 0; // to hold the count of matching elements

    // loop through the array
    for (int i = 0; i < num; ++i)
    {
        if (a[i] == average)
        {
            ++ct;
        }
    }

    return ct;
}

int equal = tableMatchingElements(table, n, average);
printf("There are %d values equal to the average.\n", equal);

The other functions are basically the same as tableMatchingElements(...), except for where you compare a[i] to the average.
e.g for greater

    if (a[i] > average)
    {
        // TODO print value of a[i]
        ++ct;
    } 
nullptr 167 Occasional Poster

I think you'll find that what you want is the DOT11_SSID member of the WLAN_AVAILABLE_NETWORK struct.

anukavi commented: Thanks and this worked. U have helped me a lot and have also learnt lot by making errors.Thanks friend +0
nullptr 167 Occasional Poster

Set the PlainText property to false, then
RichEd.Lines.SaveToFile('...\blah.rtf');
or use a TMemoryStream not a TStringStream.

nullptr 167 Occasional Poster

I'm not sure if this is what you mean, but try printf("How are you %%dad%%");

nullptr 167 Occasional Poster

Just install the 2012 VC++ Redistributable - http://www.microsoft.com/en-us/download/details.aspx?id=30679

nullptr 167 Occasional Poster

I just threw this together for testing purposes:

using namespace std;

void ReadtheFile();

string getcmd;
ifstream FileName;
char InBuffer[64];

int _tmain(int argc, _TCHAR* argv[])
{
    ReadtheFile();
    getchar();

    return 0;
}

void ReadtheFile()
{   
    size_t Data_Length;
    FileName.open("Credit.txt");
    if (FileName.fail() )
    {
        cout << "error opening file" << endl;
        return;
    }

    while (getline(FileName, getcmd) )
    {
        if (getcmd.empty() )
        {
            continue;
        }

        memset(InBuffer, 0, 64); 
        string subString_is = getcmd.substr(0, 4); // read length 4
        memcpy(InBuffer, subString_is.c_str(), subString_is.size() );

        switch (InBuffer[0]) 
        {
        case 'K': 
            if (InBuffer[1] == 'L')
            {
                memcpy(&InBuffer[4], "123456", 6);            
                memcpy(&InBuffer[10], "0987", 4);                         
            }
            break;

        default:
            break;
        }

        Data_Length = strlen(InBuffer);    
        cout << string(InBuffer) << " length: " << Data_Length << endl;             
    }
    FileName.close();
}


Credit.txt
-------------------------
KL10
PM00  

KL10
CRAP

-------------------------

Output:

KL101234560987 length: 14
PM00 length: 4
KL101234560987 length: 14
CRAP length: 4
anukavi commented: Hi, will change my code as per ur design and will get back to u. +0
nullptr 167 Occasional Poster

It would likely be worth posting more of your code rather than just the snippets we see. Otherwise all I can do is guess that it's probably a scope problem with where the variables are declared.

anukavi commented: Thanks..ok give me some time, will post it +0
nullptr 167 Occasional Poster

I have got an integer as 0010000001

Is 0010000001 binary? If it is, just shift right the number of digits to remove.

If it's just a decimal integer then num/10000 seems logical.

anukavi commented: its not binary,, its exactly 10 digit number ,so as of now foll.this logic.Thanks +0
nullptr 167 Occasional Poster

find 2 ^ k
Seeing as you can't use the pow(...) function, you could just use bit shifts.

2 << (k - 1)

2 shift left (k -1 ) will give you 2 to the power of k, where k is an unsigned whole number.

nullptr 167 Occasional Poster

Try changing the following -

line 3:   int again='y';
line 14:  again = getch();
kidpro commented: Thx dear +0
nullptr 167 Occasional Poster

what I should write beside return ?

Use cout to inform you what max is.
Pause execution before return 0; so that you can see the result.

After that, look at ways to optimize your maxValue function.

nullptr 167 Occasional Poster

Perhaps CreateTimerQueue, CreateTimerQueueTimer, DeleteTimerQueueTimer would do what you want. Plus it's easy to wrap them into a class.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682483%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687003%28v=vs.85%29.aspx

nullptr 167 Occasional Poster

Exactly as Bob suggested, just fill in the blanks.

void Reverse(char entry[ ], int length)
{
    if (0 == length) // if (!length)
        return;

    char *front = &entry[0];
    char *rear  = &entry[length - 1];
    char temp;

    while (front < rear)
    {
        // swap front/rear 
        // increment front ptr, decrement rear ptr        
    }


}
nullptr 167 Occasional Poster

Have a look from lines 13 to 16, you're writing beyond the bounds of the allocated array.

nullptr 167 Occasional Poster

You can also replace the strcpy_s(...) with the string copy member function.

    char destPath[MAX_PATH] = {0};
    char sourcePath[MAX_PATH] = {0};

    dest.copy(destPath, dest.length(), 0);
    source.copy(sourcePath, source.length(), 0);
nullptr 167 Occasional Poster
nullptr 167 Occasional Poster

To generate integers between 10 and 40 inclusive you can use:

rand()%31 + 10;

By N DISTINCT random integers, I assume that it means N different integers. So you'd have an array[N] and keep
generating random range numbers, check if they're already present in the array and if not place the number in the array until you reach array[N - 1]
You would also want to validate that the number N entered is not more than the number of integers between 10 and 40 inclusive.

TrustyTony commented: Good thinking of mathematical consequences of uniqueness: ' not more than the number of integers between 10 and 40 inclusive' +12
nullptr 167 Occasional Poster

How can I eliminate the "high, reserved byte" or ensure it is set to 0?

color = GetPixel(hdc_, 10, 10) & 0xFFFFFF;
nullptr 167 Occasional Poster
printf("factorial of (%d) = %d\n", fact, result);
printf("press Enter to exit\n";
getchar();

return (EXIT_SUCCESS);

or do you mean:



#include <stdio.h>
#include <stdlib.h>

#define fact 5

int main(void)
{
    int i, j, result;
    int _fact = fact;

    for (j = 0; j < fact; j++, _fact--)
    {
        result = 1;

        for (i = _fact ; i >= 1; i--)
        {
            result *= i;
        }
        printf("factorial of (%d) = %d\n", _fact, result);
    }

    printf("\npress Enter to exit\n");
    getchar();

    return (EXIT_SUCCESS);
}
nullptr 167 Occasional Poster

Check out IsZoomed function.

nullptr 167 Occasional Poster

Just taking the first part of the equation - 3x^3
To multiply you need to use * as in 3*x
^ is bitwise xor, do you really want to calculate 3 times x xor 3?