~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Its just a simple function of the string class. The above statement means that if the variable my_var doesn't contains any one of the characters specified in the allowed_chars variable, it will return the index of that character.

More reference can be found here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Since you are using C++ already, why not do something simple like:

// Not tested
#include <fstream>
#include <string>

int main ()
{
    using namespace std ;

    string my_str ;
    const char search[] = "model=" ;
    size_t size = strlen (search) ;
    size_t pos = 0 ;

    ifstream in ("modelset.txt") ;
    ofstream out ("output.txt") ;

    while ( getline(in, my_str).good () )
    {
        if ( (pos = my_str.find (search, 0)) != string::npos )
        {
            my_str = my_str.erase (pos, size) ;
            out << atoi (my_str.c_str()) << '\n';
        }
    }

    // close the file streams
    in.close () ;
    out.close () ;

    getchar ( ) ;
    return 0 ;
}

Modify this basic framework to suit your needs.

Oh and btw, don't PM people, its rude. If we get time, we will definately help you out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A simplistic way with the minimalistic error checking would be:

#include <iostream>
#include <string>

int main ()
{
    using namespace std ;

    const char allowed_chars[] = "0123456789" ;
    string my_var ;
    int num  = 0 ;

    cout << "Enter the account number: " ;
    cin >> my_var ;
    getchar () ;

    if ( my_var.find_first_not_of (allowed_chars) != string::npos )
    {
        cout << "The thing you have entered is not a number" ;
    }
    else
    {
        num = atoi (my_var.c_str()) ;
        cout << "The number is " << num ;
    }

    getchar ( ) ;
    return 0 ;
}

The trick here is accepting the input as a string so that you would have more control over it and validating it according to your own business rules.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The program looks good. Mind posting the line numbers and the exact errors you are getting.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Creepy, idiot librarians READ boring, historic books, terminated.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I suppose even IN can be used in the fashion you have mentioned, since Oracle doesn't have a FIND_IN_SET function.

Oh and btw, the IN clause in Oracle is really poweful since it works with literally any type of data.

select '~s.o.s~' from dual
where to_date('01/02/99', 'dd/mm/yy') in ( to_date('01/02/99','dd/mm/yy')) ;

Can MySQL do that... :P

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Brain is my favourite organ.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why not use the first ENUM set for the second selection also ?

Either that or prefix the ENUM names with an abbreviation of their purpose. Something like:

enum MenuOne { MO_FIRST = 1, MO_SECOND } ;
enum MenuTwo { MT_FIRST = 1, MT_SECOND } ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

jar, so breathless

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

to themselves that

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

stick -> heavy

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get a highlighted Shut Down button.

I put in an onion.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Declare another variable cumilative_total which will hold the cumilative value.

Do something like this at the end of the inner while loop:

score = MAX_ATTEMPTS - attempts ;
cumilative_score += score ;
printf ("The score of this round is %d.", score) ;
score = 0 ; // reset the score
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just do:

v [2][5] = 9999 ;

to insert value at a specific location in the vector.

Vectors are almost like arrays except that they are a bit more robust along with a host of features.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It feels so good to see you back. ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm thinking it would traverse all rows eliminating those where column is 123, and then go back on all of the others and check whether the value of column is in the array, so essentially that's going over nearly everything twice, no?

So you mean to say that every condition put in the WHERE clause results in a full table scan.. ? Atleast not in Oracle.

So if I were to use:

select * from Emp 
where (emp_name LIKE '%Dani%') AND
        (emp_id IN (1, 2, 3, 4, 5)) AND
        (sal > 10000) ;

would this query scan entire table containing millions of records thrice ? Logically, don't think so....

Well I did use a FIND_IN_SET() clause?

Is there no simple IN clause in MySQL ? Something like the one written by me in the above snippet ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

can be the

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I certainly don't think it would be traversing the table twice, but I guess you know your tools the best.

BTW why not just use a simple IN clause ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

to cut your

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

salt -> sugar

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Foolish, waxy LIBRARIANS enjoyed rocking historic books, related.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay so it was like 'performing operations which should never have been perfomed by the sql' sort of thing.

BTW indexing doesn't account for bad code you know...;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

FOOLISH, waxy ex-Presidents enjoyed rocking historic elections, elated.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. so was it the number of round trips made to the database or a logic problem ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get to have some Orange juice.

I put in a memory chip.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Sexy..hmm. Whatever made you say that ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

paper and scissor.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maximum number of columns in a table or view is 1000.

Read this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

scapula -> scalp

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

like the buzzing

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

<< mistake >>

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

then y is it that when i display *p for the 1st time in the main AFTER the function was called, it still manages to display the value or 3?
it only displays rubbish after i try to change the value......

Undefined behaviour. The "it works in this case, so whats wrong with it" thing is not so good to rely on. Since k in your case is an automatic variable whose scope is local to the function you have defined, its existence is and has to be limited to the function block. Any reference to the variable or its location after the function has exited is not to be relied on.

In general, returning the address of the local variable unless you have explicity requested for it (so that you can explicity free it) is a bad progamming practice, resulting in subtle bugs. Better not rely on such things.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So if you want to keep your formula unchanged, just initialize the attempts variable to 1 instead of 5, increment the variable instead of decrementing it.

Something like:

const int MAX_ATTEMPTS = 5 ;
int attempts = 1 ;

while (attempts <= 5)
{
    // your code
    ++attempts ;
}
score += (MAX_ATTEMPTS - attempts) ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get to meet Santa Claus.

I put in a golden snitch.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

sing his lore.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You get to live for a long time.

I put in a stocking.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Heaven and Hell are just a figment of your imagination.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm ... testing testing 1-2-3.

Test ... test ... another test

I guess this is the secret behind your "awesome" post count....:)

BTW a distinct lag when I hit the "Post Quick Reply" button, but other than that, its okay.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

you were taunted

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

wasted, stoned ex-presidents ENJOYED rocking historic elections, elated

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm a 5 year-old super genius. If you don't believe me, take a look at my profile:
http://www.daniweb.com/techtalkforums/member73097.html

Then I guess you ought to be banned since the minimum age is 13... ;)

Of course, no one here is going to beat iamthwee as the youngest...

:mrgreen:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Btw, I don't know exactly what you try to do with the score, but I noticed that if you guess the number at the first try your score is 0
and it seems to work properly as long as you enter in the many attempts.

A logical formula for score can be something like: score += 5 * attempts ; Also for generating good random numbers see this.

Aia commented: Great information about random numbers +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It depends on what kind of requirement is behind the rounding but you can do something like :

x = floor (0.23) ; // 0
x = floor (0.90) ; // 0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This is because you are assigning p the address of a variable k which is local to the function changep and hence k loses its existence (goes out of scope) as soon as the function exits.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

To your surprise, it floats.. ;)

I put in a scissor.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hey there my friend, welcome to Daniweb :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hey there eXceed, welcome to Daniweb. :D

We are looking forward to overflow your knowledge base... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello Tim, welcome to Daniweb buddy. :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

a hideous act.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Away, up up and away.