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

Hmm.. hey benobi1 and cosmoe, just to let you know that even though this is geeks lounge, it doesnt mean that you start posting utter crap, irrelevant to the thread which is about Miss Dani's birthday. Either stick to topic otherwise dont post. And let Miss Dani worry about her own personal life. She is not interveing doest mean that you can go ahead and poke your nose in someone's private life.

One more such incident or post , and an infraction from me is on the way.

And btw 5 infraction points = member automatically get banned.

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

Yeah that would be really good.

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

Naa you aint defining the default constructor, you are just declaring it in Complex.h but its defination doesnt occur in Complex.cpp, thats the whole root of the problem.

Implement one in complex.cpp and all should work out fine.

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

The first one and second one are okay, but the last one requires you to strain your eyes to loook at what you have written.

Best stick to the normal font, or black like in your first case and it would be really nice of you.

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

I agree that this isn't the easiest subject for a beginning programmer, but I'll try to explain:

so you can just use 'coordinates' to set and get data! For example if you say: array[2][2] = 1 ; You array will now look like this:

000
010
000

Oh so is it like that, too bad I didnt know about it.

From my understanding dont you think array[2][2] should be :

0 0 0
0 0 0
0 0 1

and not

0 0 0
0 1 0
0 0 0

;)

Indexing of array starts at zero since they are internally treated as pointers.

int array [3] -- array is single dimensional array, containing 3 elemnts
which are indexed as array [0], array[1] and array[2]

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

Yeah as long as it goes easy on the eyes of the viewer, I dont have a problem. Show me which color you are going to use ?

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

Hey there nanodano, dont you think you are overlookign something.

The syntax for templates is template < class T > and not template < typename T > Try to make the following change in your files and see if it works.

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

Okay the thing is that your code doesnt even compile. I thought maybe you had "some problem" with the code ?

The mistakes were all silly ones os i have just changed them and the y are given in red...

// #include <iostream.h> depreceated header style use the one below
#include <iostream>
using namespace std ; // use the standard namespace

 // #define MAXSIZE ]2     a closing square bracket ???
const long MAXSIZE = 12 ; // better
 
// void fillArray(float [MAXSIZE]); 
// void checkArray(float [MAXSIZE]);
//will not compile, what were you trying to achieve here. this is not a
// prototype but errror.

  void fillArray(float a[MAXSIZE]); 
  void checkArray(float a[MAXSIZE]);

 
int main(void)

{
            float rain[MAXSIZE];

            fillArray(rain);
            checkArray(rain);
            return 0;
}

void fillArray(float r[MAXSIZE])

{
            int i;
            for(i = 0; i < MAXSIZE; i++)

            {
                        cout << "Enter rainfall for month " << i + 1 << " : ";
                        cin >> r[i];
                        if(r[i] < 0)

                        {
                                    cout << "Rainfall cannot be negatige -- try again." << endl;
                                    i--;
                        }
            }
}

void checkArray(float a[MAXSIZE])

{

            float max, min, tot, avg;
            int i, maxmonth, minmonth;

            max = min = a[0];
            tot = avg = 0.0;
            maxmonth = minmonth = 1;
            for(i = 0; i < MAXSIZE; i++)

            {
                        if(max < a[i])
                        {
                                    max = a[i];
                                    maxmonth = i + 1;
                        }

                        if(min > a[i])

                        {

                                    min = a[i];
                                    minmonth = i + 1;

                        }

                        tot = tot + a[i];
                        avg = tot / (i + 1);

            }

            cout.precision(2);
            cout.setf(ios::showpoint …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tsk tsk.. thread closed.

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

Please dont resurrect dead threads like a shaman.
Thread closed.

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

Search engines are your best friends:

Google
Clusty

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
  • You get a hologram of yourself :mrgreen:
  • I put in a pirated mix-CD of Iron Maiden's best 20 songs

Hey buddy, stop using loud colors in your post. All your previous posts are also colored. Its not like it draws more attention they just end up hurting our eyes. We do get and pay attention to what is written in normal way.

Please refrain from using colors.

mattyd commented: he is correct in this +1
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Bah... I agree. I completely missed out your algorithm, my bad.

But still if the requirement also consists of reading palindrome data from a input file and then writing the actual palindrome string devoid of whitespace characters and which is case insensitive....
*how i wish* :D

Anyways thanks for pointing it out, maybe i am just growing senile in young age...

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

Hmm.. maybe something like:

  • Accpet the input from the user using fgets()
  • Remove the trailing newline at the end of the string accepted from the user. (must do, check my function remove_newline())
  • Check if the last character of the string is ! or ? by using something like:
// accept input
// remove trailing newline and replace with null character '\0'
int string_length = strlen( my_string ) ;
if( my_string[string_length - 1] == '?' || 
                          my_string[string_length - 1] == '!' )
{
    // continue with the normal functionning
}
else
{
    // duck out of program, using return 1 or exit(1) or again 
   // ask for user input
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The reason you're getting those errors is because in your header file you defined Look::Look() and Look::~Look , and neglected to implement them in look.cpp.

Maybe i am just going blind :eek:

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

Just replace the y in cout with your character.

char mychar = '*' ; // this is how we declare and initialize characters

// your loops here
cout << mychar ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. a palindrome actually doesnt consider spaces, punctuation marks and character case (upper or lower).

Maybe for a more detailed explanation, you might want to look here:
http://www.daniweb.com/techtalkforums/thread59789.html

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

yeah I got how to reverse the first loop it was the second one that is confusing me still. I should made that clear when I posted

Like Mr. Lerner said there, unless you yourself understand what looops are and how they function, it would be a tough time for you.

Just keep in mind that the inner for loop is executed outer for loop number of times.

For each iteration of outer loop,
Run the entire inner loop.

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

Okay, I will just like you to try out one thing if possible by you.

Create a new console C++ project in VS 2005. Create three blank files in it: Main.cpp, Look.cpp and Look.h

Copy and paste the contents of the original files into these files, check to see if all the new files created are in the same folder and same view.

I cant tell you the specifics of VS 2005 since its currently not installed on my computer .

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

Okay lets put it this way:

  • You need an output like:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7

  • Notice that the ending number of each line keeps on decrementing each row. For eg. its 9 for the first row, 8 for teh second row and so on.
  • So.. use a for loop which will count from 9 down to 1 (keep the variable of this for loop as outer.
  • Use a second for loop to control what gets printed. Keep the initial value of that for loop as 1 since 1 is common to each column that is printed. Name this for loop variable as "inner". Keep the terminating condition of this for loop to be less than or equal to "outer".
  • This way, your outer for loop takes care of the number of columns that should be printed while the inner for loop actually prints them.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Okay buddy, what exactly your intension is ? You have been recommended books in the prevoius posts by Mr. Dragon and Mr. Joe. Refer the previous posts for answer to your question.

I'll tell you a cheap way of learning C++. Read the plethora of tutorials available on the net. Maybe then you will get a hang of things and would be in a condition to decide which books are good for you on your own.

So for the time being:
> Grab a free compiler Dev C++
> Google some "beginner C++ tutorials"
> Get started.

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

Hmm... are all the files in the same folder ?
Have you checked the project settings of visual studio for this particular project ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
int main(void)
{
    long double sourcebase; 
// why long double, why not just long or
//  int. long is sufficient for your needs.
// also initialize variables as you declare them to avoid bugs

     int targetbase = 0; // initialize variables, good practice
    int tmp_number = 0;
    int* new_number = NULL;
    int  flag = 0 ; // to check whether number entered is valid or not

    // pull stmts which dont require validataion out of loop
    printf("Enter a positive number: ");
    scanf_s("%d",&tmp_number);
    printf("Enter the destination base: ");
    scanf_s("%d",&targetbase);

    do 
   {
        flag = 0 ;
        printf("Enter the base of that number: ");
        scanf_s("%d", &sourcebase);

        if( (sourcebase<2) || (sourcebase>10) )
        {
             printf ("You number is invalid!!!!!!!\n\n");
             flag = 1; 
         }
    }
   while( flag );

 int i=0;
 int decimal=0;

while( temp_number ) // you forgot something ?
    {
        decimal += (tmp_number % 10) * pow( sourcebase, i ) ;
        tmp_number /= 10 ;
        ++i ;
    }


//  int decimal=0; // remove this since this will reset the decimal value we just calculated

 while( decimal )
    {
        new_number[i] = decimal % targetbase ;
        decimal /= targetbase ;
        new_number = (int*) realloc( new_number, i + 2 ) ;
        ++i ;
    }

 // printf("You number is:%d",new_number);
// The above is the incorret way of printing values of an array
// Loop through the various elements like
// eg. long* my_array = {1, 2, 3, 4} ;
// for( .... )
// { print values }
    
return 0;
    }

I hope you are understanding the things …

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

how do you become a mod?
there should be like tryouts, id be interested

It is basically a popularity contest. The super mod comes up with your name in the MOD forum, other mods voice their thoughts regarding your work and attitude and many other things. If you earn a majority, you are in. So keep posting and wait for the time when vacancies arrive:mrgreen:

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

The reason you are not able to find the damn problem is because the way your winner function is designed. A function which spans almost 3 pages in C++ has some serious design problems.

Try splitting the function into logical componenets, maybe that would help you localize the problem. Since i dont know the game, cant help you a lot but looking at that function sure seems like a lot is getting repeated which could have been made into a single logical unit

Hope it helped, bye.

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

Arent the comments clear enough to make so that you can yourself do the documentation ?

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

I as it becomes a double , I cant use % with the double. and

Just to let you know there is a function there is a function [search]fmod(double x,double y)[/search] which exactly does the same thing.

But as Mr. WaltP has already pointed out, dont use double if your aim is to find out prime numbers.

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

When you say, it doest work, it is very vague. Sifting through someone else's code is really difficult. Since your program is written in modular way, say which parts work properly and which dont.

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

Show us what you have got so far and we will definately help you out.

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

Hmm please post your entire code so that i can have a look at it. My best guess is that you have declared new_number as an array of integers, which should actually be an integer pointer.

You must have done: int new_number [4] ; But you should have done: int* new_number = NULL ; Post your code which shows what you have done so far.

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

Hmmm... realloc is the memory management function which really makes the job of dynamic memory allocation actually "dynamic".

Dynamic memory when allocated using malloc , returns a pointer to the allocated peice of memory or memory block. But if the user wants to dynamically increase the size of the memory allocated to the same pointer, malloc wont do hte job.

To expand or to allocate more memory to the pointer which already has been allocated memory using malloc , we use realloc ( reallocation of memory ).

Consider this snippet:

// result stored in the dynamically allocated integer array with
// one slot
    int* new_number = (int*) calloc( sizeof( int ), sizeof( int ) ) ;

    i = 0 ;
    while( decimal )
    {
        new_number[i] = decimal % target_base ; 
        decimal /= target_base ;

        new_number = (int*) realloc( new_number, i + 1 ) ;
// we need more memory, which will be controlled by the counter i 
// hence while reallocing we use i as reference. So when i = 1
// allocate (2 + 1) = 3 slots and so on.

        ++i ;
    }

realloc takes two arguments, the first one being the pointer which has to be reallocated memory and the second one being the new size of the memory to be allocated.

For more info look here:
http://www.cplusplus.com/ref/cstdlib/realloc.html

Hope I have been helpful , bye.

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

Try replacing #include <asm/io.h> to #include <sys/io.h> and tell me what you get.

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

while (temp_number) means continue with the loop while temp_number is not 0. Inside the loop I am dividing the temp_number with 10 ( temp_number /= 10 ) so the loop ends when this value reaches 0.

eg.
Initial value = 129
129 / 10 = 12
12 / 10 = 1
2 / 10 = 0 ( loop ends )

Hope it made matters a bit clear for you.

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

UNO on XBOX Live :)

Sheesh man... :mrgreen:

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

while constructs and for constructs are both looping constructs -- you can use either one of them for looping purpose if thats what you wanted to ask. decimal += (tmp_number % 10) * pow( source_base, i ) ; Here decimal is the var which will hold the decimal value of the entered number with the base "source_base". To it we iteratively add the digit * source_base ^ i.

Here digit is obtained by doing tmp_number % 10 while i controls the exponent value.

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

Okay I will give you the algorithm, you just try to implement it.

  • Accept the number, the source base and the target base from the user.
  • convert the given "number" having base "source_base" into decimal using the formula:
while( tmp_number )
    {
        decimal += (tmp_number % 10) * pow( source_base, i ) ;
        tmp_number /= 10 ;
        ++i ;
    }
  • Now we have the decimal equivalent of the number in "decimal"
  • Create a dynamic array uisng pointer to int which will hold the individual digits of the new number of the target base.
  • Using the given formula convert from decimal to your base.
while( decimal )
    {
        new_number[i] = decimal % target_base ;
        decimal /= target_base ;
        new_number = (int*) realloc( new_number, i + 2 ) ;
        ++i ;
    }
  • In the end you would get your required number by traversing through the integer array.

Hope it helped, bye.

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

First LUA version: for i = 1,10 do print(i) end

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

You actually wanted num_string as char array( C style string) but have declared it as being char which will hold only one character.

char num_string = '\0' ; // wrong
char num_string[BUFSIZ] = {'\0'} ; // correct, will now hold a number string

Also can you give a sample output your program is supposed to display, since it would help in clearing hte problem stmt which is not so apparent to me, seeing your imcomplete implementation.

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

Hmm.. hey buddy is there a problem with your code or you want to submit an example to help others out ?

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

Select the edge with the minimum cost.

Maybe you should try lookiing at the followign places:

The algorithm:
http://students.ceid.upatras.gr/~papagel/project/pseukrus.htm

The simulation:
http://students.ceid.upatras.gr/~papagel/project/kruskal.htm

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

THe sum of all hours or the total hours would be the sum of the individual hours which you accept from the user in th for loop. SO the logical thing would be to add to the total hours, the value of hours entered by the user.
Something like:

int total_hours = 0 ;
int total_charge = 0 ;

for( int i = 0; i < 3; ++i )
{
    // accept input from the user as "num"
    // calculate the charge for the hours inputted by user as "charge"

   total_hours = total_hours + num ;
   total_charge = total_charge + charge ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. I think there is some kind of misunderstanding here Mr. WaltP. His requirement is that the palindrome should be case insensitive as well as "ignore whitespace characters".

My first reaction is why bother with strtok()? This is a simple program of characters, not tokens.

Okay now i will try explaining my logic behind this. The OP wants the algo to ignore whitespace characters. So suppose your string is A (50 spaces) b (\n\t\t) B (100 spaces) a Trying to loop through the whole string to ignore whitespace characters is not feasible, would jsut result in reinventing the wheel when we have good inbuilt functions to handle such kind of situations. strtok is just the kind of thing we need here IMHO. Comments are welcome.

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

Dont worry about the code tags, its our daily routine to correct posts. Remember it though for the next time.

BTW just wanted to tell you that its 03.30 here :P ( so its never too late to code)

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

Ok that is a very good effort on your part.
I will write a crude code for you and will let you do the research on the inbuilt functions of C which i have used in achieveing the task.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char palindrome(char *,int);

/**
 * This function is used to remove the trailing new line which is normally present at the end of the string accepted from the user
 * using fgets( ).
 */
 void remove_newline( char* input )
{
    // loook up this func also at www.cppreference.com
    char* p = 0 ;
    if( p = strrchr( input, '\n' ) )
        *p = '\0' ;
}

char palindrome( char my_string[], int length )
{
    if( length < 2 )
        return 1;

    if( my_string[0] != my_string[length - 1] )
        return 0;
    else
        return palindrome( my_string + 1, length -2 );
}

void make_lower( char* input )
{
    // make string lowercase
    int i = 0 , string_length = strlen( input );
    while( input[i] != '\0' )
    {
        input[i] = tolower( input[i] ) ; // use std function to make string lowercase
        ++i ;
    }
}

char* format_string( char* input )
{
    // look up the function strtok, fgets, strcat and calloc at www.cppreference.com
    char* result = NULL ;
    char delimiter[] = " "  ;
    char* new_string = (char*) calloc( strlen( input ) + 1, sizeof( char ) ) ;

    result = strtok( input, delimiter ) ;
    while( result != NULL )
    {
        printf( "\ntoken: …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. recursive palindrome checker.

As far as the ignoring spaces part is concerned, it would be better if you purged your string of spaces or newline characters before passing it to the Palindrome checker function. That way it would be cleaner and easier.

As far as the algo for recursive implementation is concerned, the logic is same as the recursive one, but you just need to write the function so as it can be called recursively.

  1. Create a function "is_palindrome()" which accepts the C style string which has to be checked for and the size of the string.
  2. During the first pass, the function would be supplied with the pointer to the start of the string and the original string length.
  3. Check if the strign length is less than one, if yes then the given string is a palindrome and return 1 or success. This is one way in which the function will be terminated.
  4. Now check if the first char of the string is the same as the last character. If yes then call the function again but this time with the character pointer incremented by one (to point to the next character under consideration) and the size parameter decreased by 2 ( since we have tackled two characters already-- the first and the last)
  5. If the first character is not equal to the last character, there is no point in continuing the function. Return failure or 0. This is the second terminating condition of hte …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah... now this is what many people who start on programming say, give up early and think they can never do it.

Keep going on and on, keep asking help, keep on practicing and you would be surprised at how good a coder you are ;)

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

It's part of a code example from my prof. I'm still really green on this stuff. Any help would be appreciated.

Looks like there is some problem with my browser of the forum coz the code i am trying to put to help you out is not showing up

Visit this link for the template help:
http://www.cplusplus.com/doc/tutorial/templates.html

and try to run the code below and see if it works.

template < class T > 
class typeClass
{
private:
T myArg; 
public:
};

template <class T> 
void something(T myArg)
{
T thisArg = myArg;
std::cout << thisArg << endl;
}

int main()
{
int i = 22;
float f = 22.3;
char * ch = "hello";
something(i);
something(f);
something(ch[1]);
string s = "world";
something(s);
typeClass<int> myClass;
 
return 0;
}

Hope this helped, bye.

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

Huh.. where did you come up with the weird syntax from...

//template <typename T> ----> wrong way of using templates
template < class T > 
class typeClass
{
private:
T myArg; //---->I was trying to use 'T myArg'
public:
};

template <class T> // correct way

void something(T myArg)
{
T thisArg = myArg;
std::cout << thisArg << endl;
}

int main()
{
int i = 22;
float f = 22.3;
char * ch = "hello";
something(i);
something(f);
something(ch[1]);
string s = "world";
something(s);
typeClass<int> myClass;
 
return 0;
}

Hope this helped, bye.

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

My post was intended for programmers who are thinking of learning VB for developing quick GUI applications.

Those who know VB, i agree dont need to learn anything new.
But those who dont, why bother learning VB which comes for a price (i mean you have to buy the studio) if you have Python and third party libraries at your disposal. ;)

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

Many problems in your code to begin with:

  1. Dont use conio.h its a non standard header file ( you seem to be using Turbo C )
  2. Dont use clrscr() to clear the screen. Its a non portable function which works only on Turbo C. Use it at your own risk
  3. What you are trying to do is called "finding whether a string is Palindrome" i.e. if a word both in its original form and reversed is the same. eg. deed, civic
  4. Are you sure you want to accpet the input character by character ? Because normally input is accpeted in form of strings.

If you want in string form then consider something like:

#include <stdio.h>
#include <string.h>

void remove_newline( char* input )
{
    char* p = 0 ;
    if( p = strrchr( input, '\n' ) )
        *p = '\0' ;
}

int main( void )
{
    int i = 0 , j = 0;
    char buffer[BUFSIZ] = {'\0'} ;

    printf( "Enter the string: " ) ;
    fgets( buffer, BUFSIZ, stdin ) ;
    remove_newline( buffer ) ;

    int length = strlen( buffer ) ;
    char* my_string = (char*) malloc( length + 1 ) ;

    for( i = 0, j = length - 1; j >= 0; --j, ++i)
    {
        my_string[i] = buffer[j] ;
    }
    my_string[i] = '\0' ;

    printf( "The new string: %s", my_string ) ;
}

Though its a lengthy way, but is simple to understand for a beginner.
Make the required changes if you …