David W 131 Practically a Posting Shark

You may have other errors ... best to post the whole section (or program).

/*
char year= "YYYY";
char month="MM";
char day= "DD";
*/

/*  But ... I suspect you want to have: */

const char* year= "YYYY";
const char* month="MM";
const char* day= "DD";
David W 131 Practically a Posting Shark

A quick Google turned up this ... (for starters)

http://www.cprogramming.com/tutorial/function-pointers.html

...

Callback Functions
Another use for function pointers is setting up "listener" or "callback" functions that are invoked when a particular event happens. The function is called, and this notifies your code that something of interest has taken place.

...

You might want to start with function pointers ... like you may wish to use when passing in a different compare function to a library sort ... to sort on different fields, etc... ?

David W 131 Practically a Posting Shark

Perhaps the OP means ...

'under what star' was that DOB ?

If so ... then the programmer needs a program that has a table of 'Stars' and dates (or date ranges) ...

The program can loop to ask the user to input a (VALID) date of birth ...

then ... code a look up of that DOB in the table

then ... report

then ask for another 'star / dob' combination to find ... or quit.

Now ... just code a working shell program (with comments like the above) ... and the OP will be 'on target' ... with ... step 1 DONE!!!

Can you code a 'Hello World!' program in C++ ?

Can you code a loop that asks for more?

Can you prompt for C++ string user input and take in a string in a C++ string (variable)?

Can you do a TABLE LOOK UP ... to see if a string is in a table?

Can you report the matching item in the table, if lookup was successful?

These are tasks needed above.

To see some of these tasks demonstrated, you could check here:

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

David W 131 Practically a Posting Shark

Also ... you will have much more joy in your coding in C when you find some regular ways to easily handle the problem of char's left in the input stream ...

After input ... often left are char's like the '\n' char at the end of a line.

These 'left over' char's ARE a BIG problem for new coders ... so the sooner you see the easy fixes, the sooner you will enjoy coding in C :)

(These 'left-over' char's ... will mess-up you next attempt to enter anything ... since those 'left-over' char's are ALL-READY there ... in the input stream, before you enter anything else ... they will be taken for the next input.)

When inputing (SINGLE word - NO spaces) strings, using scanf, you need to specify a max field width ... (so that you do not overflow the string size into other memory and crash the program or something?)

If spaces may occur in your input strings, use fgets to get the whole line ... and then fix that input by stripping off the '\n' char at the end ... or flushing the input stream if the buffer (size) did NOT hold the whole line ... (if that is what you want.)

Also, when passing struct's that hold more bytes than the bytes in the address size you are using ... pass the address (pass by reference ... NOT by value) ... to save making a copy of ALL that data in the struct ... …

Ancient Dragon commented: agree +14
David W 131 Practically a Posting Shark

I think "Schol-R-LEA" meant to type:

using namespace std; // :)

It it always good, (especially for beginner coders), to start out with a working shell C++ program like 'Hello World' ... that compiles and gives the exact expected output ...

Then ... add a few lines ... (or a function, etc) ... and re-compile and test the output ... and fix till it works.

If there is a bug in the added new block of code, you will know 'where to look' ... just look in that added (small) block of code ... most probably :)

Always keep a copy of your last working 'step'. Then, if you can-not find the bug in your next stage of added code, you can always go back to a working program and add a smaller (compiling / working?) block of code.

// use comments to document what you want to do 
// at each stage
// this function prints out the values in
// an int array called 'ary' with size 'size'
void print( const int ary[], int size )
{
   for( int i = 0; i < size; ++i ) cout << ary[i] << ' ';
   // print newline at end
   cout << endl;
}
David W 131 Practically a Posting Shark

Since your are using C++, why not rather use C++ strings?

// structStudent.cpp //  // 2014-02-25 //

#include <iostream>
#include <string>

using namespace std;


struct Student
{
private:
    string firstName;
    string lastName;
    string telephone;

public:
    void set_firstName( const string& fn ) { firstName = fn; }
    void set_lastName( const string& ln )  { lastName = ln;  }
    void set_telephone( const string& ph ) { telephone = ph; }

    string get_firstName() const { return firstName; }
    string get_lastName()  const { return lastName; }
    string get_telephone() const { return telephone; }

    void takeIn()
    {
        cout << "Enter first name :  " << flush;
        getline( cin, firstName );

        cout << "Enter last name  :  " << flush;
        getline( cin, lastName );

        cout << "Enter telephone  :  " << flush;
        getline( cin, telephone );
    }
    void print() const
    {
        cout << "Student info: " << endl;
        cout << "Name: " << firstName << " " << lastName
             << ", Telephone: " << telephone << endl;
    }
} ;


// vs ...
void takeIn( Student& s )
{
    string tmp;
    cout << "Enter first name :  " << flush;
    getline( cin, tmp );
    s.set_firstName( tmp );

    cout << "Enter last name  :  " << flush;
    getline( cin, tmp );
    s.set_lastName( tmp );

    cout << "Enter telephone  :  " << flush;
    getline( cin, tmp );
    s.set_telephone( tmp );
}
void print( const Student& s)
{
    cout << "Student info: " << endl;
    cout << "Name: " << s.get_firstName() << " " << s.get_lastName()
         << ", …
David W 131 Practically a Posting Shark
string spc( 3, ' ' );
cout << '*' << spc << '*';

Is short code ...

But ... what is a 'word' ? Does it need to be a real word that is in the English dictionary? If so ... that is NOT what you are doing.

See this for starters on a dictionary lookup for your words ...

// twoWords.cpp //  // 2014-02-24 //

// program to be able to take in two words and
// compare them ... outputing the words from word1 which
// are also in word2 and ... vice-versa.

#include <iostream> // for cin, cout
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm> // re. find

using namespace std;

typedef vector< string > VecStr;

char takeInChar( const string& msg )
{
    cout << msg << flush;
    string reply;
    getline( cin, reply );
    if( reply.size() )
        return reply[0];
    // else ...
    return 0;
}
bool more()
{
    if( tolower( takeInChar( "More (y/n) ? " )) == 'n' )
        return false;
    // else ...
    return true;
}


int main()
{
    string word1, word2; //declaration of words

    // Welcome message
    cout << "------------------------------------------------\n"
         << " Topiloe's Text Analyzer - Release 1.0 \n"
         << "------------------------------------------------\n\n";

    cout << "Enter two words on one line (separated by a space): ";
    cin >> word1 >> word2;

    string dummy;
    getline( cin, dummy ); // eat '\n', etc... that's still at end of cin stream

    cout << "The words entered were: " << word1 << ", " << word2 << …
Ezekiel_1 commented: The words I meant are the strings that will be entered by the user +0
David W 131 Practically a Posting Shark

If you were to use stringstream objects, your file conversion from ..

7 regular data 'words' on each line ...

to ...

all 7 sequential words on their own sequential line,
(with the exception that the 2nd and 3rd words are both on the 2nd line, separated by one space) ...
If you were to use stringstream objects, your file conversion from ..

7 regular data 'words' on each line ...

to ...

all 7 sequential words on their own sequential line,

(with the exception that the 2nd and 3rd words are both on the 2nd line, separated by one space) ...

This becomes really easy, (once you see the facility of using stringstream to parse a line) ...
This becomes really easy, (once you see the facility of using stringstream to parse a line) ...

// fileLineToSequenceData.cpp //  // 0213-08-19 //


#include <iostream>
#include <fstream>
#include <sstream> // re. stringstream obj's ...
#include <string>


using namespace std;

const char* FNAME_IN = "inDat.txt";
const char* FNAME_OUT = "outDat.txt";


/*
10BCE0014       Manohar Khanna 4 CSE613 CSE501 CSE613
10BCE0023       Vijay Ahari 4   ENG401  CSE503  CSE401
10BCE0147       Prakhar Dixit   4   CSE503  CSE623  CSE501
11BCE0258       Abdul Kadir 3   ENG301  CSE502  CSE613
11BCE0321       Rahul Garg  3   ENG301  CSE503  CSE501
11BCE0326       Bhavya Jain 3   CSE301  CSE421  CSE512
12BCE0026       Rakesh Kapoor   2   ENG201  CSE302  CSE303
12BCE0265       Sonam Krishna   2   ENG401  CSE512  CSE413
12BCE0413       Vinay Khatri    2   ENG201  CSE301  CSE203
13BCE0002       Karan Lodha 1   ENG102  CSE102  CSE301
13BCE0041       Shyam Gupta 1   ENG101  CSE101  CSE102 …
David W 131 Practically a Posting Shark

You said you were learning C++ ... but did you realize that your code was in the C style?

In C++, one can pass by reference ... and so will not have to dereference a value passed into a function using the * dereference operator (that is used with passed in pointers that one wants to dereference)

And note that main returns an int

so it is ...
int main() // not void main()

jandanielsaclolo commented: Thanks! +0
David W 131 Practically a Posting Shark

1.

If you know the range of values in the integer matrix 'm', say the values range form 10 to 1009
then you could create an array to hold the counts for each value

// initial all values to 0
int freq[1000] = {0};

//then you could run though the matrix
//and ...
++ freq[ m[i][j]-10 ];

/*

for each i, j in the nested inner loop

then skipping on 0 values in the freq array

just report the freq each value (index goes from 0, 999 but values are (index +10) )

*/

2.
Another way would be to use a struct that holds the value and the freq of that value
and a vector to hold the structs

the first time a values occurs (that is, that value is not already in the vector of struct)
push_back a struct with that value and the count = 1

every time an element in the matrix is aleady in the vector of struct, just ++ the count

David W 131 Practically a Posting Shark

Mary ...

Well learning how to write to file and read back from file, is a basic thing to learn, the OP does not seem to be using any file operations here :)

Note:

a lot of the time, rather then using an if ... elseif ... else structure

or a switch ... case structure

a 'table look up' will do very nicely ... and could save a lot of redundant coding:

#include <iostream>
#include <sstream> // re ostream objects ...
#include <string>


using namespace std;

const size_t MAX_CHARS[] = { 5, 10, 15 };

const string LEVELS[] = { "EASY", "NORMAL", "HARD" };


// returns a non-empty string with a max string length of char's
std::string takeIn( const std::string& msg, size_t maxStrLen )
{
    std::string val;
    for( ; ; ) // loop forever ... until break
    {
        std::cout << msg << std::flush;
        getline( std::cin, val );
        size_t len = val.size();

        if( len && len <= maxStrLen )
            break;

        if( len ) std::cout << "\nOnly " << maxStrLen
                            << " char's allowed here\n";
        else std::cout << "\nBlank line not valid here.\n";
    }

    return val;
}




int main()
{
    cout << "Welcome to 'CAN YOU GUESS MY NUMBER'\n\n";

    int difficulty;
    int pass = 0;
    bool done = false;
    while( !done )
    {
        cout << "Choose your difficulty: \n\n"
             << "1: Easy\n"
             << "2: Normal\n"
             << "3: Hard\n"
             << "0: Quit\n\n"
             << "Enter your choice: 0-3: " << flush;

        cin >> difficulty;

        if( cin.fail() )
        {
            cin.clear(); // in case NON …
David W 131 Practically a Posting Shark

Here is a shell that shows one popular student way to start a menu / choice / switch type program.

Note the use of functions to facilitate your logic flow and code developement testing steps.

Note the use of getline for input so that the WHOLE line is input.

#include <iostream>
#include <string>

using namespace std;


void lev1( )
{
    cout << "\n\nLevel 'Easy' is being developed ...\n";
}
void lev2( )
{
    cout << "\n\nLevel 'Normal' is being developed ...\n";
}
void lev3( )
{
    cout << "\n\nLevel 'Hard' is being developed ...\n";
}

int showMenuGetChoice()
{
    cout << "\nWelcome to 'CAN YOU GUESS MY NUMBER?'\n\n"
         << "Choose your difficulty: \n"
         << "1: Easy\n"
         << "2: Normal\n"
         << "3: Hard\n"
         << "0: Quit\n"
         << "Enter your choice 0..3 : " << flush;
    string line;
    getline( cin, line );
    if( line.size( ) != 0 ) return line[0];
    // else ...
    return 0;
}

void pauseForEnter()
{
    cout << "\nPress 'Enter' to continue ... " << flush;
    string line;
    getline( cin, line );
}


int main()
{
    bool done = false;
    do
    {
        switch( showMenuGetChoice() )
        {
            case '1' : lev1(); break;
            case '2' : lev2(); break;
            case '3' : lev3(); break;
            case '0' : done = true; break;
            default: cout << "\n\nYou have made an invalid choice.\n";
        }
    }
    while( !done );

    pauseForEnter();

}