WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A couple other things worth noting:

1: do{}while((c = fgetc(input)) != '\n');
Why a do-while? Why not just while((c = fgetc(input)) != '\n');??

2: fseek(input, -1, SEEK_CUR);
Why? Can't you do something better/cleaner than messing with the file pointer?
It looks like you're already handling the case without the fseek().

3: printf("%c", c);
This is a very expensive statement to use for character output. It's much cleaner to use putchar().

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also printf() is a very expensive way to output a single character. Better to use putchar('*') because it's made specifically to output a single character.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The calls to srand() should ideally be placed at the top of main(), and only once.

Is this necessary ? I mean will my code run improperly? Would be please elaborate. Thanks.

Yes. srand() initializes the random generator. It does not need to be initialized more than once. The way you have them now it's probable that the two initializations will happen within the same second. That guarantees the same random numbers.

So, if you call srand() at exactly 10:53:20 and get 10 random numbers you might get
1 5456 812 32700 1325 54 622 29953 2 9834

If all that takes less than 1 second, your next call will happen at 10:53:20 and the next 10 random numbers will be:
1 5456 812 32700 1325 54 622 29953 2 9834

Not very random, eh?
So calling srand() must be done only once at or near the beginning of the program -- at the top of main() or in an initialization function that is guaranteed to be called only when the program starts.

Try this:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    int rnd;
    int i;
    int j;

    for (j=0; j<4; j++)
    {
        srand(time(NULL));
        cout << "Test #" << j << ":  ";
        for (i=0; i<12; i++)
            cout << rand() << " ";
        cout << endl;    
    }

    return 0;
}

Then move the srand() outside the loop and run it again.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

cin.get(); is not working for me to pause the console window.

Then your basic input concepts are leaving the input buffer dirty. Change your cin>>timinput to a getline().

So if I have "08:30" as timein, and "17:30" as timeout the result of difftime() must be 9.5. timediff=difftime(timeout,timein)..

How do you get 9.5? That looks wrong to me.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you display the values in your tm structures to verify the data is correct? If it isn't, there's no sense comverting anything.

Also, please format your code so it can be read and understood easier. When you get into more complex programs this will be a major help to you. Also, stop using system("pause"). Here's why

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not bad...

Here are some possible things you could consider for improvements:

------------------
Because coinval is a #define it should be in all caps. And while you're at it, define the heavy and light values too:

#define COINVAL 2
#define COINHEAVY 3
#define COINLIGHT 1

Also, make the values for typeOfCounterfeit into #defines as well:

#define TYPELIGHT 'L'
#define TYPEHEAVY 'H'
#define TYPEANY   'A'

These changes remove the need to use hard coded values in the code itself and you can make modifications very quickly and accurately by not searching through the code.

------------------
The function gameInfo() might be better named gameInitialize()

------------------
If you want to limit the number of coins to 12,
1) test for invalid values
2) don't make the array dynamic -- it's a waste of time and you won't need the delete

------------------
At the prompt "Press (H) for heavy counterfeit, (L) for light\n and (A) for computer to decide : ", what happens if you press K, or h, or a? Test for valid values.

------------------
All but the calls at the bottom of gameGenerate() could be put into gameInitialize() since it's all initialization.

------------------
The calls to srand() should ideally be placed at the top of main(), and only once.

------------------
For the test of typeOfCounterfeit you can use a switch(). It would make that section of code more compact.
Another option to testing 3 possibilities for typeOfCounterfeit is …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This looks like a homework question, and a fairly specific one at that. It looks like something from a programming intro course/tutorial, not an algorithms course.

Probably very true, but we have a long-standing guideline that when you simply post requirements with no details, no questions, and no code you are seen as someone wanting us to do your homework for you. So you get what you get in the way of advice.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use getline() or some equivalent function that reads an entire line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know how to work with structures yet?
If so, it's no different from what you already know.
If not, you might want to wait until you get to the chapter on structures before tackling this program.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You're darn lucky Narue isn't here. Your eyes would burn! You're welcome.

I_m_rude commented: :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

don't know the idiom in proper manner

Then why are you complaining and thinking it's an insult? Touchy, aren't you?

As for the rest of your rant, there was no question to be answered. So, as you guessed in #4, what could I answer?

What the heck does #3 mean? Have you gone crazy?

why are you so lazy for this ?

Why are you being rude to shashikumar? Then call me rude? You may need to understand this concept (पाखंडी)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And why is the kettle calling the pot black?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Of course.

Parse the string into it's components (a 17 and a 30).
Fill a time structure (defined in time.h) with the appropriate values.
Call the appropriate time function in to convert the structure into time_t.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Refer to point 1, 9, and 10 above.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ok, done. Now what?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, if you don't understand stringstream there are two avenues:
1) Don't use stringstream
2) Learn how stringstream works by writing a bunch of test programs that will teach you various aspects of it.

Also your formatting needs a lot of work. You code is almot impossible to read and follow. See this.

Note how much easier this is to read:

    do {
        Suma = 0;
        Sumb = 0;
        cout << "\n" << "What is the numerator? \n";
        cin >> numerator;                           //Input for the numerator
        cout << "\n" << "What is the denominator? \n";
        cin >> denominator;                         //Input for the denominator
        /*cout << "How many plus signs exist in the numerator? \n";
        cin >> re;                                  //Input for number of plus signs*/
        cout << "What is the lower boundary? \n";
        cin >> xmin;                                //The lower boundary
        cout << "What is the upper boundary? \n";
        cin >> xmax;                                //The upper boundary
        cout << "In what increments do you wish to integrate? \n";
        cin >> inc;                                 //Steps between each calculation, increases calculation time
        string term = "000x^000";                   //Test term
        x = xmin;                                   //Sets x to the first value
        xmax -= inc;                                //Prevents inaccuracy due to the upper boundary
        TurnPlusesToSpaces (numerator);             //Calls earlier function
        //cout << numerator << "\n";                //Outputs the numerator
        stringstream ssa(numerator, stringstream::in | stringstream::out);
        //cout << terma << "\n";
        TurnPlusesToSpaces (denominator);           //Calls earlier function
        //cout << denominator << "\n";              //Outputs the numerator
        stringstream ssb(denominator, stringstream::in | stringstream::out);
        //cout << termb << "\n";
        do 
        {
            while …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The Dragon gave you a major clue. Try reading about fscanf() and try some things. Testing is the best way to learn.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ahh, OK. Thanks.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Another approach is to use the strtod(const char* nptr, char** endptr) function.

You could use boost::lexical_cast to try and convert the string to a number

I'm curious how these two approches actually test for valid values. Won't they both simply convert whatever it can to binary and stop when an invalid character is seen? The OP did say

need to check whether all digit is numeric.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First, is there any way that I can do this more efficiently, ...

First thing is compile the program and fix the errors. There's generally no reason to enhance a program that won't compile in the first place or runs improperly.

...and second, what is the easiest way to do this using arrays.

Completely depends on what you need the arrays for. Just adding arrays for the sake of adding arrays is not a good idea. I can see at least two ways you might add arrays. Come up with a reason and the way usually shows itself.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I havent tested the above code?

Why not? How do you know what needs to change if you haven't bothered to try it?

Any correction?

Too much to go into. Based on what you've posted you need to go way back to the basics. Like
1) the infamous Hello World program for basic program layout
2) basic input into integer variables
3) basic comparison (if) statements
4) not understanding what time_t variables are

Did you do a search for info at all?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am able to successfuully build my DOS aps under this compiler on WinXp, I wouldn't try to run it though.

Why not? I've successfully built and run Turbo 1.0 graphics code in WinXP.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are correct.

That still doesn't change the fact that recursion is a loop. The term loop depends on code executed, not on data addresses used

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Calling main() from within main() would be an example of recursion, and not looping.

its not loop. Its just "calling the main function" we don't consider it a loop.

Actually, it's called a recursive loop, so yes, recursion is a loop.

A loop is a programming construct that repeatedly executes some code while a certain condition is true.

Which is exactly what recursion does.

But the rest of the information here (for the most part) is correct enough. You should never call main() as a function.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I like option 1. I don't need to automatically see comments, but when I want to see them it would be nice to have "show comments" only when there are comments.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry. If it only works in Dev-C++ then there's something terribly wrong. You should be able to compile C code in any C compiler. It that better?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

None that I know of, since C is not controlled by a single company like Java.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If it only works in Dev-C++ then there's something terribly wrong. You should be able to compile C++ code in any C++ compiler.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes it is. Your solution is leaning toward code you can find at this site. Most is quite precise, but.... ;o)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry this is late, but I haven't used it in a while. If this doesn't help, nothing will:

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Anybody knows where the problem is?

It's on (or near) the line mentioned in the error. Unfortunately, when you don't tell us the line, or indicate the line because the post numbering is different than your code numbering, it kinda hard to pinpoint the where. Please remember to post all pertinant information necessary to help us help you.

Now in this case, I see a major faux pas. On the line
if (strcmp(static_cast<char>(line.getline(PlayerID,2,'\n')),respcode)!=0)
(which I suppose is your error line) why are you
1) reading data
2) calling a function
3) casting data
4) testing data
all in one line? Split it up into multiple appropriate statements so you can see exactly what you are doing. This often helps in understanding not only the code but any problems that arise.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But what is not undertandable now?

What you need to accomplish. What you don't understand. What borders are. Why you need to write this. Why you are so thickheaded. Among other things dealing with this thread.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what google can ?

Damn, you're useless.

Can anyone please explain...

I_m_rude commented: Damn rude and insultive. be away! +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Google can

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

sir i got error 112th line

Sorry, but that's what you get for using someone else's code and not fixing your own code. You don't understand what he did and can't fix it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And yet another "not totally working" post, as if we're supposed to know what that means. When asking for help, give us information. Don't make us guess what "not working" means.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Posting your errors will do more.

Also, using the same parameter types that you defined in the method would do wonders to reducing errors. Look up how to define parameters vs making the call. You're close, but making a silly mistake.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How 'bout Employee::Calculate(parameters) ????

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why would you want the data explosed to the outside? Use a get method to expose the location.

If you want to see the value of location 0,0, return the location with
val = level1.getMapLoc(0,0);

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Consistent formatting is the key. See this and refine your indentation. I believe this will fix your problem when you indent properly.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm not sure what the situation is in India where the original poster is from...

But you can bet the boxes are programmed using Turbo C....

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As someone who knows very little of conio.h,...

Please reread my post.

But if you insist on knowing worthless programming trivia, here's a start

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then don't use it. Write your own version and you'll know how it works.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Does anyone know what I am doing wrong?

Mainly, if it's supposed to be a string, where's the space for the \0 that terminates a string?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Run program and see
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

but when it comes to memory storage or allocation its better to go in this way,time efficience compare to using the third or temp variable

Really? Please show us why 4 extra bytes for a temp variable is slower than all that math. What are your sources for this assumption of speed vs memory useage? Document your position.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I would recommend you stay away from all practices/function/headers that are compiler/OS dependent. Unlearn conio.h since only 1% of the compilers ever made have it defined. And of those compilers, each conio.h is different.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Repeating your first post does not qualify for explaining IN DETAIL. IN DETAIL means explain every little thing we need to understand the problem.