David W 131 Practically a Posting Shark

Look at the
'if ... else ...'
examples I gave you of different tests
and branching to different sections
by set / reset of 'flag' values
and see if you can code the exact solution that you wish?

If you get stuck ...
take a deep breath and 'think'

If ( condition is true ) do this
else do that

and try again ...
and if still stuck ... show the code you tried.

David W 131 Practically a Posting Shark

... but i missed the part where if a player rolls a 1,
the score should not be added to his total so it'll be the second players to roll.
i couldnt seem to get that command to work so far;
any idea?

Take a look at this demo ... that has ADDED EXTRA ROLLS for the 'computer' ...
if the 'computer rolls' certain values ...

/* rollDice2.c */  /* 2015-10-15 */

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

/*
     ... i missed the part where if a player rolls a 1,
     the score should not be added to his total
     so it'll be the second players to roll.
     i couldnt seem to get that command to work so far;
     any idea?

     BUT added here...
     if computer rolls 1, 3, 5 then computer rolls again ...
*/


/* prototypes for 3 handy utilities for many C student coding problems ... */

/* a simple student way to handle numeric input ...
   so program won't crash on bad input */
int takeInInt( const char* msg );
int takeInChr( const char* msg );
int more(); /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */



void showDice( int randNum );
void playGame();




int main() /* ******************************************* */
{
    do
    {
        playGame();
    }
    while( more() );

    return 0;
} /* **************************************************** */




void playGame()
{
    int gameTotal = 0, player = 0, computer = 0;
    char choice = 'p'; /* start with player, 'c' is for computer …
David W 131 Practically a Posting Shark

@Ashik_2 ... did you NOT read the previous post before yours?
THIS was/is a dead thread.

David W 131 Practically a Posting Shark

... have things ever got so slack around Dani's place ... in the last several weeks ?

So many ... dead threads ... now ... being resuscitated?

David W 131 Practically a Posting Shark

Hey @ Zain_4 ...

Do you realize that it is not proper etiquette to hijack a thread?

If you wish to ask a new question, please start a new thread ...

and if you need programming help with an homework question ...

you will NEED TO FIRSTLY show us the code that you have tried so far ...

so that we may see how to best help you.

David W 131 Practically a Posting Shark

You may also like to learn how to program using the Python computer programming language :)

David W 131 Practically a Posting Shark

This should help ...

http://plantation-productions.com/Webster/www.artofasm.com/Windows/HTML/HelloWorlda3.html#998367

http://plantation-productions.com/Webster/www.artofasm.com/Windows/HTML/images/HelloWorld5.gif

ALSO see:

https://en.wikipedia.org/wiki/Endianness

to see why what you say is possible output ... IS UNLIKELY ... unless you do some special handling with the bytes and word data

David W 131 Practically a Posting Shark

Oops ... see following ... duplicate accidently posted here.

David W 131 Practically a Posting Shark

An other very simple and fast way to handle your card closeness problem could be to do a TABLE LOOKUP ...

//card_look_up.cpp //
 // includes etc...
// ...
const string CARDS[] = { "A1", "A2", "B1", "B2" };
const int NUM_CARDS = sizeof CARDS / sizeof CARDS[0];

// do a liner search ...
// or could do fast binary search ... if 'in order' //
int getPosIn( const string ary[], int size, const string& x )
{
// return index+1 if found
// return 0 otherwise
}

// presumption here is that BOTH x and y ARE IN ary of strings
int howClose( const string ary[], int size, const string& x, const string& y )
{
    int posX = getPosIn( ary, size, x );
    int posY = getPosIn( ary, size, y );
    return posY-posX;.
}
David W 131 Practically a Posting Shark

Oops ... missed fixing a typo within the 30 minute allotted edit time...
There was an erroneous period (.) between 'void' and 'print() const'
Now fixed in modified class Student example below:

class Student
{
 public:
     // ctor ...
     Student( const std::string& name="", id=0 ) : name(name), id(id) {}

     void print() const
     {
         std::cout << name << ' ' << id;
     }
private:
    std::string name;
    int id;
} ;
David W 131 Practically a Posting Shark

You seem lost with repect to coding for a class (or a struct?) in C++

You best start simple ...

Here is a simple example of using a C++ struct with a constructor ...

Note:
in C++ the contents of a struct have default state of 'public'
in C++ the contents of a class have default state of 'private'
OTHERWISE ... a class and a struct are the same.
You can change the (default) status by begining a block of code with a label like this:

struct Student
{
private:
    std::string name;
    int id;
 public:
     // ctor ...
     Student( const std::string& name="", id=0 ) : name(name), id(id) {}

     void.print() const
     {
         std::cout << name << ' ' << id;
     }
} ;

Here is a simple guessing game example that could give you ideas to help ease your coding ...

// class_Guess.cpp //


#include <iostream>
#include <sstream> // re. stringstream
#include <string>
#include <ctime> // re. time
#include <cstdlib> // re. srand, rand


using namespace std;

const int MAX_NUM = 100;


// some nice little utitities to ease student coding ... //
int takeInInt( const string& msg, int min, int max )
{
    int val;
    while( true )
    {
        cout << msg << flush;
        if( cin >> val && cin.get() == '\n' )
        {
            if( min <= val && val <= max )
                break;
            cout << "Valid input range here is "
                 << min << ".." << max << " ...\n";
        }
        else
        {
            cout …
David W 131 Practically a Posting Shark

Hey there @ Rodrigo_2 ...

Did you know that it is not good manners, in help forums like this,
to "hijack" some other persons "thread" ?

If you really hope to get help,
then please start a new thread with your particular question.

Note:
you MUST also show the code you have tried so far
so we can see how to best help you.

If you have no clue how to get started,
there are MANY online tutorials ...
like this one for example:

Six Fast Steps to Programming in C
http://developers-heaven.net/forum/index.php/topic,2022.0.html

Or this ...
First steps ... via example programs in C++ and C
http://developers-heaven.net/forum/index.php/topic,134.0.html

David W 131 Practically a Posting Shark

See example solutions to common beginner problems ...

1) take in valid int (with a prompt) so program won't crash
2) keep stdin flushed as you go ...
3) loop while more
4) takeInChr( withpromptStr ) to ease getting user choices

This demo may help you get started with clean working code ...

Note:
This demo does NOT entirely conform to the spec's you were given,
but is meant to help you get started.

/* rollDice.c */


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

void showDice( int randomNumber );
void playGame();


/* 3 handy utilities for many C student coding problems ... */
int takeInChr( const char* msg );
int more(); /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */
/* a simple student way to handle numeric input ...
   so program won't crash on bad input */
int takeInInt( const char* msg );




int main()
{
    do
    {
        playGame();
    }
    while( more() );

    return 0;
}





void playGame()
{
    int gameTotal = 0, player = 0, computer = 0;
    char choice = 'p'; /* start with player */

    srand( time(0) ); /* seed rand... */

    printf( "Welcome to the GAME of PIG ... \n\n" );

    gameTotal = takeInInt( "Enter the game total (for example 40): " );

    while( player < gameTotal && computer < gameTotal )
    {
        char roll;
        if( choice == 'p')
        {
            printf( "It's time for player ... \n" );
            do
            {
                roll = takeInChr( "Your choice roll or hold (r/h) …
David W 131 Practically a Posting Shark

You need to start coding, implementing the steps you were given ...

and then to show us the code you tried.

Re. the unclear graphic output part ... you will have to clear that up with the source.

David W 131 Practically a Posting Shark

I would firstly take in a validated binary string ... then convert that.

David W 131 Practically a Posting Shark

A first approach might be to use a struct to order all the cards in the deck

struct Card
{
   int value;
   char suit;
   int place; // 0..51 //
} ;

Then could use the 'place value' to compare cards ...

David W 131 Practically a Posting Shark

The code ? maybe ? something like this:

template< class T >
void tqkeInAndInsertItem( TreeClass< T >& tree )
{
    cout << "Enter item: ";
    T tmp;
    cin >> tmp; // MUST HAVE defined >> for type T //
    tree.insert( tmp );
    cout << "Item inserted:" << tmp; // MUST HAVE defined << for type T //
}
David W 131 Practically a Posting Shark

This (working) example may give you some more ideas about how to get started ...

// meanMedianMode.cpp //

// a start //


#include <iostream>

using namespace std;

const int MIN_SIZE = 5;


int takeInInt( const char* msg )
{
    int val;
    while( true )
    {
        cout << msg << flush;
        if( cin >> val && cin.get() == '\n' )
            break;
        else
        {
            cout << "Invalid input ... numbers only!\n";
            cin.clear(); // clear error flasgs
            cin.sync(); // 'flush' cin stream ...
        }
    }
    return val;
}

void print( const int* ary, int size )
{
    int i;
    for( i = 0; i < size; ++ i )
    {
        cout << ary[i] << '\t';
        if( (i+1) % 8 == 0 ) cout << endl;
    }
    if( i % 8 != 0 ) cout << endl;
}

double getAverage( const int* ary, int size )
{
    double sum = 0;
    for( int i = 0; i < size; ++ i )
        sum += ary[i];

    return sum/size;
}




int main()
{
    int size = 0;

    for( ; ; )
    {
        size = takeInInt( "Please enter the array size: " );
        if( size >= MIN_SIZE ) break;
        cout << "Try again ... size must be >= " << MIN_SIZE << " ...\n";
    }

    int* ary1 = new int [size];
    int* ary2 = new int [size+1];
    ary2[0] = 0;

    // take in new values ... and put into correct places


    for( int i = 0; i < size; ++ i )
    {
        cout << "For 'int' …
David W 131 Practically a Posting Shark

I think the project is not well worded ...

and also, it seems to me to be poorly thought out,
since creating an 'hole' for a new value ...
at the front of an enlarged array ...
this is usually handled by an 'insert' function
or ...
in a linked-list ... by a push_front function.

But ultimately here ...it seems you are to maintain 2 dynamic arrays of integers ...

For the first one, you need to firstly prompt and have the user input the size
then (prompt and) input that many integers in a loop to fill up all the slots

Then get new memory to hold an array of int's that has size+1 slots

Then the thing to do now, since all the values in array one at index 0..(size-1)
are to be copied to array 2 at index 1..size ... is to just copy them over ...

Then set value at slot with index 0 in array 2 to value = 0

Then you need to use functions for each of ...

getMode, getMedian and getAverage ... and also showAry

but for getAverage, getMedian, getMode, you will be working on 'ary one'

double getAverage( const int* ary, int size )
{
    double sum = 0;
    // sum up
    return sum/size;
}

Then could sort array one in increasing order ...
(a simple bubble sort would do ok for small size arrays used here)
and report middle value …

David W 131 Practically a Posting Shark

You may get a few coding ideas from the related examples here:

http://developers-heaven.net/forum/index.php/topic,2022.msg2680.html#msg2680

David W 131 Practically a Posting Shark
David W 131 Practically a Posting Shark

If you will show us the code thta you have tried, then we may be able to help.

David W 131 Practically a Posting Shark

Please start a new thread with each new question.

If you are wishing for help with an 'home-work' problem ... you firstly NEED to try to code a solution yourself ...

AND THEN (and only then) ..

submit what you have coded ... along with a description of your problem.

David W 131 Practically a Posting Shark

It's over due to get a modern C++ compiler that uses standard C++

Hints:
srand( time(0) ) ; // seed rand

int x = rand()%2; // x is now 0 or 1

int ary[] = {10, 100};
int y = ary[x]; // y is now 10 or 100
...

David W 131 Practically a Posting Shark

What C++ compiler are you using?
It would help to show your programs output also.

David W 131 Practically a Posting Shark

This example to a similar problem may help you to rethink / restart your code.

// rowsOfStars.cpp //

// demo of a way to accept ONLY VALID inoput  ...//

/*
    So i am new to c++, I don't know what is wrong with my program,
    I keep looking for the issue but can't find why it won'r run.

    So i am trying to develop a program which reads the numbers
    the user inputs and convert those into rows of asterisks.

    ...

*/


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring> // re. strlen //

using namespace std;

const unsigned COLS = 60, ROWS = 5;


/* 2 handy utilities for many C student coding problems ... */
int takeInChr( const char* msg )
{
    cout << msg << flush;
    int chr = cin.get();
    if( chr != '\n' ) while( cin.get() != '\n' ) ; /* flush stdin ... */
    return chr;
}
bool more() /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */
{
    int c = takeInChr( "More (y/n) ? " );
    if( c == 'n' || c == 'N' ) return false;
    /* else ... */
    return true;
}



int main()
{
    char ary[ROWS][COLS+1] = {0}; // + 1 to '\0' terminate //

    unsigned numStars;
    unsigned row = 0, col;
    for( ; ; )
    {
        cout << "How many stars for row[" << row
             << "] (valid entries here 0.." << COLS << ") : " << flush;
        if( cin >> numStars && cin.get() ) // …
David W 131 Practically a Posting Shark

Here is how I might start to tackle a problem like this ...

Note the comments in the program to find all the .h files needed to test it out.

You can find file "CvecOfString.h" at:
http://developers-heaven.net/forum/index.php/topic,2580.msg2865.html#msg2865

You can find file "readLine.h" at:
http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

You can find file "Cvec.h" at:
http://developers-heaven.net/forum/index.php/topic,2580.msg2862.html#msg2862

The following program assumes that you already have a big dictionary text (.txt) file (pre-fixed, sorted and all lower case words) available.

/* makeWordsFromLetters.c */  /* 2018-09-19 */


#include <time.h> /* re. srand( time(0) ); */

#include "CvecOfString.h" /* also includes readLine.h, Cvec.h  ...
                             which also include ... (look in files, to see) */

/*
find "CvecOfString.h" at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2865.html#msg2865

find "readLine.h" at:
     http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

find "Cvec.h" at:
     http://developers-heaven.net/forum/index.php/topic,2580.msg2862.html#msg2862

*/




const char* FNAME = "fixedWords.txt";

const char* HEADER1 =
    "This game asks how many letters (3 to 7 ): your wordLen = ?\n\n"

    "It then builds a dictionary of words with that length, \n"
    "   from a big dictionary of words ...\n\n"

    "It then randomly selects (makes a copy of) a word from that built list,\n"
    "   then scrambles the letters of the copy and displays it. \n";

const char* HEADER2 =
    "It then asks the user to enter a word, using as many letters as possible, \n"
    "   from that C string of scrambled letters. \n"
    "It then compares the user entered word to the BIG dictionary of words\n"
    "   using a binary search …
David W 131 Practically a Posting Shark

Do you know how to (start the) code for a C++ class?

Show us as much as you can ... (i.e. fill in your code for) :

#include <iostream>
// ...

class Teacher
{
public:
    // ...
private:
    // ...
} ;

class Student
{
    friend class Teacher;
public:
    // ...
private:
    // ...
} ;


int main()
{
    // ...
}
David W 131 Practically a Posting Shark

Further to @Dani comments ...

Naming conventions like using ALL_CAPS
for global const values
helps the reader 'see'
that the value is a 'global const value'

Using descriptive names also helps the reader
follow the 'logic flow'
and
lends to 'self documentation as you go'

David W 131 Practically a Posting Shark

A next step might be to use functions to get valid input in a loop?

Also maybe use a struct tp hold the 'counts'?

Take a look:

// countPosNeg.cpp //  // 2015-0915 //

#include <iostream>

using namespace std;


struct Counts
{
    int pos, neg;

    // default ctor...
    Counts() : pos(0), neg(0) {}
} ;


int takeInInt( const char* msg )
{
    int val;
    while( true )
    {
        cout << msg << flush;
        if( cin >> val && cin.get() == '\n' )
            break;
        else
        {
            cout << "Invalid input ... numbers only!\n";
            cin.clear(); // clear error flasgs
            cin.sync(); // 'flush' cin stream ...
        }
    }
    return val;
}

int takeInChr( const char* msg )
{
    cout << msg << flush;
    int c = cin.get();
    cin.sync();
    return c;
}

bool more()
{
    int c = takeInChr( "More (y/n) ? " );
    if( c == 'n' || c == 'N' ) return false;
    //else ...
    return true;
}




int main()
{
    Counts cts; // construct with default values //

    do
    {
        int i = takeInInt( "Enter an integer: " );
        if( i >= 0 ) ++cts.pos;
        else ++ cts.neg;
    }
    while( more() );

    cout << "Out of " << (cts.pos+cts.neg) << " numbers, you entered "
         << cts.pos << " positive and " << cts.neg << " negative.\n";

    takeInChr( "Press 'Enter' to exit ... " );
}
JamesCherrill commented: We need more code like this - real structure vs one endless block +15
David W 131 Practically a Posting Shark
David W 131 Practically a Posting Shark

If you just want the 'inclusive count of numbers'

enter beginning number in beg
enter ending number in end
inclusive count of numbers is: end-beg+1

David W 131 Practically a Posting Shark

You could try code like the below example, that uses these .h files:

Note: you can find needed (include) files as per below ...

CListOfString.h
http://developers-heaven.net/forum/index.php/topic,2582.msg2882.html#msg2882

readLine.h
http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

Clist.h
http://developers-heaven.net/forum/index.php/topic,2582.msg2877.html#msg2877

/* split2.h */ /* this version: 2015-08-07 */

/* http://developers-heaven.net/forum/index.php/topic,46.0.html */

#ifndef dwSPLIT_H
#define dwSPLIT_H

#ifndef DELIMITS
#define DELIMITS  " \t"
#endif

#define NUM_DLMTS  sizeof(DELIMITS) -1

#include "ClistOfString.h"
/* adds readLine.h which adds stdio.h, stdlib.h, string.h, myAssert, newCopy */
/* also adds "Clist.h" */

/*
CListOfString.h
http://developers-heaven.net/forum/index.php/topic,2582.msg2882.html#msg2882

readLine.h
http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

Clist.h
http://developers-heaven.net/forum/index.php/topic,2582.msg2877.html#msg2877
*/

#ifndef PUSH_CLIST
#define PUSH_CLIST  push_backClist
#endif



char* newSubStr( const char* start, const char* end )
{
    int len = end-start+1;
    char* newCpy = newMem(len);
    strncpy( newCpy, start, len );
    newCpy[len] = 0;
    return newCpy;
}

void split( Clist* lst, char* p1 )
{
    char *p2, *p3;
    List ml; /* ml is really a ... node/element/record in a List ... */
    for( ; ; ) /* loop forever ... until break */
    {
        p3 = p1;
        while( *p1 != 0 && strchr(DELIMITS, *p1) ) ++p1;

        if( p1 != p3 )
        {
            ml.str = newSubStr( p3, p1-1 );
            PUSH_CLIST( lst, &ml );
        }
        if( *p1 == 0 ) break; /* i.e. if empty or all delimits */

        p2 = p1+1;
        while( *p2 != 0 && !strchr(DELIMITS, *p2) ) ++p2;
        ml.str = newSubStr( p1, p2-1 ); /* new copy in new memory in ml.str */
        PUSH_CLIST( lst, &ml ); /* default is push_backClist …
David W 131 Practically a Posting Shark

Late edit to above: better to substitute above function with this function ...

template< typename T >
bool isValid( const string& str )
{
    T tmp;
    istringstream iss( str );
    if( iss >> tmp
    && iss.eof() ) // The 2nd test ensures entire string converted. //
    {
        return true;
    }
    // else ...
    cout << "Field value " << str << " not valid\n";
    return false;
}
David W 131 Practically a Posting Shark

Both of your test files ...

https://www.daniweb.com/attachments/2/d01478039506623f9c6fedd582703af8.txt

https://www.daniweb.com/attachments/2/da9dcdde1e01ed1698cce4689c5ff447.txt

... seem to be valid when (only roughly) tested like this:

// fileReadValidate.cpp //  // 2015-09-01 //

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

const char* FILE_IN  = "five09_15.79 KB.txt"; // "csv_file_78.11_KB.txt"; // // "five09_15.79 KB.txt"; //

template< typename T >
bool isValid( const string& str )
{
    T tmp;
    istringstream iss( str );
    if( iss >> tmp ) return true;
    return false;
}

bool isValidIntRange( const string& str, int min, int max )
{
    istringstream iss( str );
    int tmp;
    iss >> tmp;
    if( tmp < min || tmp > max )
    {
        cout << "Date field value " << tmp << " not in range " << min << ".." << max << '\n';
        return false;
    }
    return true;
}

bool isValidDate( const string& str )
{
    if( str.size() == 10 )
    {
        if( str[2] == str[5] && str[2] == '/' )
        {
            if( !isValid< int >( str.substr(0,2) )
                || !isValid< int >( str.substr(3,2) )
                || !isValid< int >( str.substr(6,4) ) )
            {
                cout << "Invalid date field ... non integer day or month or year ...\n";
                return false;
            }
            else
            {
                if( !isValidIntRange( str.substr(0,2), 1, 12 ) )
                {
                    cout << "Invalid month field\n";
                    return false;
                }
                if( !isValidIntRange( str.substr(3,2), 1, 31 ) )
                {
                    cout << "Invalid day field\n";
                    return false;
                }
                if( !isValidIntRange( str.substr(6,4), 1900, 3000 ) )
                {
                    cout << "Invalid year field\n";
                    return false;
                }

                return …
David W 131 Practically a Posting Shark

Here is a link to a C++ split function that you might like to use in your data validation program. Reading the size of the list formed from each split up line ... will tell you right away how many fields (strings) were present in each line ... then you can traverse the list of strings for that line ... validating that each is 'acceptable' ... or not.

http://developers-heaven.net/forum/index.php/topic,2584.msg2930.html#msg2930

David W 131 Practically a Posting Shark

'Eyeballing' is not sufficient here ... You need to validate each line and every field in each line, with a short data validation program that matches the data field requirements of your original data processing programs. That fairly short and easy to code program can just read every line till done ... then using perhaps stringstream objects ... or a custom 'split' function ... parse every field in that line to make sure all fields there are expected (and each is correct type and in valid acceptable range) and thus that no extra or corrupted fields are present.

David W 131 Practically a Posting Shark

If you are writing to a data .txt file ... and then trying to read that file ... before closing and reopening it ... that also will be a problem.

You can write a short program to validate the data in your .txt files ... each line seems to have 10 regularly occurring fields ... that you can confirm if all exist ok. If data files are all fields ok ... then you have isolated the problem to be with the programs.

David W 131 Practically a Posting Shark

What does your program do?

Could you resend two files:
1st good file that process ok
2nd bad file that crashes

David W 131 Practically a Posting Shark

So add a 'newline' char to the end of the bad '2nd' file to make it match the ending in the 'good 1st' file and try it then.

David W 131 Practically a Posting Shark

You could start with some definitions like this:

const double EPSILON = 0.000001; /* change here to what you want */

/* define the function to integrate ... */
double f( const double x )
{
    return x*x - 3*x  + 2;
}

/* numerical method to get area inder curve of f(x) from x = beg to x = end ... */
double areaTraps( const double beg, const double end, const double dx )
{
    double x, area = 0;
    for( x = beg; x < end; x += dx )
        area +=  (f(x) + f(x+dx)) / 2.0 * dx;
    return area;
}

Then in main, you could do something like this:

double dx = 0.1;

/* get an initial approx. value for area_2 ... */
double area_2 =  areaTraps( 2, 8, dx ),
       area_1;

do
{
    area_1 = area_2; /* save copy of previous area estimate ... */
    dx /= 10;
    area_2 = areaTraps( 2, 8, dx ); /* get a closer estimate */
}
while( fabs( area_2 - area_1 ) > EPSILON ) ;

printf( "Area was %.6f and size of last 'dx' was %.16f ", area_2, dx );

getchar();
return 0;
ddanbe commented: Most helpfull +15
David W 131 Practically a Posting Shark

@Gribouillis ...

Thank you for the more Pythonic example code ... (and ref.)

I suspected that might be the case in Python :)

David W 131 Practically a Posting Shark

And here is an example of the above ... to get you started:

/* daysBetween.c */ /*  2015-08-29 */

#include <stdio.h>
#include <math.h>


const int DAYS_IN_MONTH[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

/* 2 handy utilities for many C student coding problems ... */
int takeInChr( const char* msg )
{
    char chr;
    printf( msg ); fflush( stdout );
    chr = getchar();
    if( chr != '\n' ) while( getchar() != '\n' ) ; /* flush stdin ... */
    return chr;
}
int more() /* defaults to 'true'/'yes'/'1' ... unless 'n' or 'N' entered */
{
    int c = takeInChr( "More (y/n) ? " );
    if( c == 'n' || c == 'N' ) return 0;
    /* else ... */
    return 1;
}


/* returns 1 if is leap year, else returns 0 ... */
int isLeap()
{
    char reply = takeInChr( "Is this a leap year (y/n) ? " );
    if( reply == 'y' || reply == 'Y' ) return 1;
    if( reply == 'n' || reply == 'N' ) return 0;

    /* if reach here ... loop again ... */
    printf( "You must enter a letter in range yYnN! Try again ...\n" );
    return isLeap(); /* an example of tail recursive call / loop  ... */
}

/* take in month, day and return day number ... */
int dayNumber()
{
    int i, month, day, daysInMonth, numGood, numDays = 0, leap = 0;
    for(  ; ; ) /* …
David W 131 Practically a Posting Shark

Firstly, please see the comments about clearing up your code, at your other post.

https://www.daniweb.com/software-development/c/threads/499170/program-which-compute-number-of-days-between-two-dates

You also have not followed the spec's you were assigned.

  • You are to repeat the task (could use calling a function in a loop) until the precision is (at least) 3 places of decimals.

  • You are to take the area of a trapezium (not a rectangle as you have done) and the area of a trapezium is: ((height1 + height2) / 2.0) * base

David W 131 Practically a Posting Shark

Without you stating the particular problem with which you wish to have help ...

here are several ways to begin to clear up your code and make it easier to see if logic and code ok:

  • Indent blocks of code.

  • Use descriptive variable names.

  • Use functions (a function for each task.)

  • Use comments and blank lines to document what is happening in each section of your code ... as you go.

  • Take in only valid input ... and do not let program crash if input was invalid.

David W 131 Practically a Posting Shark

Without seeing all the code you are using ... we can only guess at the problem(s), according to our own experience.

Inspect the good (working ok) 1st file ... by loading it into a text editor, like notepad, and see if there is one and only one newline char at the end of the last line of data there ... or if instead, that last line ends with EOF ? (i.e. NO newline char there.)

Then, make sure, (using a text editor), that the 2nd file ends like the first.

This will resolve the problem if the issue is (only) related to how you program reads lines of data and in particular the last line.

Another possible issue is the possibility of unrecognized char's being embedded in the 2nd data file chunk ... and then, the program may be halting with an exception thrown there ... but check out first idea above .. firstly ... as that 'data file (corruption and/or ending) problem' is suggested by the original two data .txt files you presented.

David W 131 Practically a Posting Shark

This may get you started ...

# removeSimilarItems.py #  # 2015-08-29 #

lst = [ ['e', 1, 2], ['e', 2, 1], ['e', 1, 2], ['e', 2, 3] ]

lst2 = []

for item in lst:
    if item in lst2 or [item[0], item[2], item[1]] in lst2:
        pass
    else:
        lst2.append( item )

print( lst )
print( lst2 )
David W 131 Practically a Posting Shark

Welcome to Daniweb.

Please note!

We will be able to help you if you firstly show us the code you have tried so far ...

David W 131 Practically a Posting Shark

We will be able to help you if you firstly show us the code you have tried so far ...

David W 131 Practically a Posting Shark

The longer (2nd) file length is given as 194.93 KB

The shorter (1st and good) file length is given as 78.12 KB

Did you not see 'a problem' with (all) the (missing) contents of the (supposed to be) longer file?

Note: I am looking at/comparing the two .txt files using my iPhone.