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

For whom the bell tolls - Metallica

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

Renowned paladins of Egypt trade magic spellbooks while breeding slick Cairo cats.

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

You get a broken home.

I put in some bleach.

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

rednecks - pullovers

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

curt

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

Matters ? Hmm..shouldn't it be mattresses.

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

Oh going off topic is one thing which we all Mods are good at... ;)

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

science and technology

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

Word change game is one of the games I play here.

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

Implement the way employee records are handled in an organization. The organization consists of Managers, Clerks and Salesmen.

Managers receive bonus, clerks get paid for overtime and salesmen get commission depending on their sales.

Also write a method which will calculate the net salary of any type of employee. For eg. for managers net salary would be "salary + bonus", for clerks it would be "salary + overtime" etc.

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

A go go - Ga ga

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

The n / 2 does not aid in checking for prime numbers. Remove it and you still would get the same answer. It just helps in cutting down extra processing and iterations.

Also read my first post for a better optimization.

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

You can save iterations and the additional checking performed in the loops by doing something like:

#include <iostream>

int main ()
{
    using namespace std ;

    int limit = -1, count = 1 ;
    bool isPrime = true ;

    cout << "Enter the limit: " ;
    cin >> limit ;
    getchar () ;

    cout << 2 << endl ; // handle special case since 2 is the only even prime number

    // the number of loops are cut in half by the use of i+=2 since
    // only odd numbers can be prime ( except for 2 which is even )
    
    for (int i = 3; i < limit; i+=2)
    {

        // there is a theorem which states that a number if not prime 
       // has to have factors less than equal to its own square root
        for (int j = 2; j * j <= i; ++j)
        {
            if (i % j == 0)
            {
                isPrime = false ;  // since factor found hence not prime
                break ;
            }
        }
        if (isPrime)
        {
            ++count ;
            cout << i << endl ;
        }
        else
        {
            isPrime = true ;  // reset the flag for next number
        }
    }

    cout << "The number of random numbers in the given range are : " << count ;
    getchar () ;
    return 0;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Efficiently making your way around shows your enthusiasm.

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

High paladins of Egypt trade magic hats while plundering vulnerable Cairo cats.

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

which we all

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

You surprisingly get Bill Gates.

I put in some ice cubes.

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

lures

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

we all are

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

Songs about Jane - Janes Addiction

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

It was an attempt at humour/humor/being funny...

Guarding yourself against all known hazards, are you... ? ;)

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

> I'd really appreciate a link to a standard specification either for C (?) or for Daniweb, seriously.
It comes from practice. Just look around and read the code snippets and posts contributed by experienced people and you would know.

> Ok, it does not exactly work like that, however, please inform me on how returning 1, 2..... is
> newbie code? Why because I don't subtract them?

As for your implementation, read the actual specification of the strcmp function. Making your own functions which performs in a different way only adds to the confusion.

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

> Well if he is learning then he is a beginner. So what is your point?
So we have to make sure they doesn't pick up wrong programming practices.

All this time you seem to be ignoring, my and Joe's constructive criticism. This is not the way things are done. A working code is not the same as a concise, clear and helpful code. You have to understand that the code which you post in the code snippets section is used and referred by thousands of beginners everyday. A high standard has to be maintained.

Picking at people who have been here for a long time is no solution to the problem. Try to improve yourself.

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

Lazaro, make sure your code is up to the specified standards like Joey said. I see a lot of beginner style programming which may confuse other people trying to learn the language.

for (i=0;i<len1 && i<len2;i++) {
    if (str1[i] < str2[i])
        return 1;
    else if (str[i] > str2[i])
        return 2;
}
return 0 ;
}

It should be something like: (not the exact implementation)

{
    for (i=0;i<len1 && i<len2;i++) {
        if (str1[i] < str2[i])
            return str1 [i] - str2 [i] ;
        else if (str[i] > str2[i])
            return str1 [i] - str2 [i]
    }
return 0 ;
}

though I would even modify the loop to make it better, but then again, its okay.
This is not how string comparision function works. The string comparision functions returns the ASCII difference between the strings if they are unequal while a zero if they are equal.

Why try to write a half baked comparision function when the library itself provides for its implementation.

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

Ankit, like Iamthwee said, strcmp ( ) coupled with qsort ( ) function should work out to be fine in your case.

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

Maybe yes, but given the imcomplete problem statement, getting to the actual requirements is kind of guesswork. The best we can do is guide him in what he is asking. The abstraction touch would be too much for the OP.

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

Here is a minimalistic working program.

#include <iostream>
#include <fstream>
#include <string>
using namespace std ;

int main (void)
{
    ifstream in ( "a.txt" ) ;
    string input ;
    char ch ;
    int value ;

    cout << "Enter the keyword: " ;
    getline (cin, input) ;

    while ( in >> ch >> value )
    {
        if (input [0] == ch)
            cout << ch << " is present in the file and its value is " << value ;
    }

    getchar () ;
    return 0;
}

/* a.txt contents

a 1
b 2
c 3
d 4
*/

If you can't figure this one out, maybe you should read some tutorials on the internet and strengthen your concepts.

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

I need to know what kind of problem you are facing with the code. Is it a compiler error, a runtime error or logic error ?

If the file contains only character and index, you can pull them in a character variable and an integer variable respectively. Accept the input from the user in the form of string, check the first char of the string. If it is the same as any one char present in the file, then you have found a match.

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

Do you want something like this:

XXXX
 XXX
  XX
   X

If so then you can do something like:

  • Run an outer loop which will move from 1 to n.
  • Run an inner loop which will move from 1 to n.
  • If the inner loop counter is less than the outer loop counter, print a space or else print the required character.
  • Print a newline at the end of the inner loop.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Eat the rich - Aerosmith

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

Murder Inc. -> Life penalty

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

You get a serious "hmm" from the Daniweb members.

I put in some oil.

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

But the information you provided is very minimal. What exactly are the data types of the variables defined and declared in the snippet you pasted.

Would you like to compare or search for a single character in Alpha [a] which I have no idea what it holds ?

And btw, you can't compare a single character with a whole string, if thats what you are planning to do...

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

Maybe something like this or this.

Though it would be of no use to use if you don't have a firm grasp of the language.

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

strcmp only works with C style strings and not single characters and strings. You are comparing a single character with a string which is wrong.

If you want to compare two characters, you can do something like:

int comparision_result = strncmp ( str1, str2, 1 ) ;

though it can be simply done with a comparision operator.

if (str1 [0] == str2 [0])
{
    // do something
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

To break down the deck[] element to get back the face and shape, you can do something like:

// Assuming the face and shape are seperated by a space
int space = deck[i].indexOf (' ') ; 
String shape = deck[i].substring (0, space) ;
String face = deck[i].substring (space + 1, deck[i].length()) ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think of it

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

Rockability - Rockafella

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

Caveman - Jimmy Eat World

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

Disappointment I feel, darkness it breeds.

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

You get Memsaab.

I put in some cashews.

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

Many many happy returns of the day my "underpaid hacker" friend... :D

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

situations where we

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

Hello there Michael, welcome to Daniweb. :D

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

High druids fromPersia trade magic carpets while plundering worn-out treasure men.

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

altering

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

I guess it will depend on the coding standards of the company you are working for. Here are two implementations of the function which finds the index of an element in the array and returns -1 if not found.

// MULTIPLE RETURNS

int indexOf2 (int array[], int length, int element)
{
    for (int i = 0; i < length; ++i)
    {
        if (array [i] == element)
            return i ;
    }
    return -1 ;
}

// SINGLE RETURN

int indexOf1 (int array[], int length, int element)
{
    int index = -1 ;

    for (int i = 0; i < length; ++i)
    {
        if (array [i] == element)
        {
            index = i ;
            break ;     // btw even break and continue are frowned upon
        }
    }
    return index ;
}

Take your pick... ;)

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

Better stay away

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

poorhouse - power house

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

Assignment statements always return true, so the if statement is always true, irrespective of the value of found before this statement.

Well, not exactly. See this snippet:

int main (void)
{
    int i ;

    if ( i = 0 )
    {
        cout << "I AM entering the IF block" ;
    }
    else
    {
        cout << "I AM NOT entering the IF block" ;
    }

    getchar () ;
    return 0;
}

The answer as we all know is "I AM NOT entering the IF block".