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

i havn't given any of the code. which code r u talking abt?

Ahh, you got the point -- maybe. But then again, maybe not.

Jishnu commented: great indirectness :) +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

in that case can anyone point me to where there is a very detailed tutorial on how to use ifstream ?

I guess I was too subtle. Post your code as the link describes. Very often if we see the code we can figure out what to tell you. So far we're only guessing.

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

I'm clueless as to how to fix the errors in this contact information manager program. please help. Thanks in advanced

You're welcome in advance.

Out of 290 lines you aren't really asking us to guess what lines have errors and what the errors are, are you? Details, please...

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

Line 60 is wrong in your code, and lines 88-92 are close....

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

Maybe this will help. Note the title...

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

:)

What was that post? A bump? Never bump your messages. Someone will get to you when they log in.

string == strcat(string," ");
		string == strcat(string,temp);

What do you think these lines are doing? I'll bet it's not what you expect....

$ is a weird character that show up. i don't know what it is.

It's called a dollar sign. Hex value 24, decimal 36.

Be more careful with your formatting

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

The array being filled with the order could simply contain the item numbers being ordered, one element per ordered item. Example, if the array contained 1,1,2,1,3,3, then 3 dogs, 1 fry, and 2 lemonades were ordered. Then at end of order, use each element of the array as an index into a cost array, which contains 1.25, 1.00, .75.

Or set up the array to be the number of items, each item being an element of the array. IOW, array[0] is for "hot dog". Example: 3,1,2 would be the same order as above. Then to total, multiply each array value with the cost array from above.

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

It would make more sense to use HEX values rather than DECIMAL. 223 is relatively meaningless, but 0xDF makes sense since each character is immediately translatable into binary:
D = 1101
F = 1111

223 would be considered a 'magic number' and should be avoided.

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

Rename if you want to , I agree(anyway you do not need my pr...) because ....

No, you need to make useful titles. And since we are an English speaking community, I really don't know what "pr" means...

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

@waltp

Sorry but i am new to this community..i didnt know about this....i will take care of this in future..

So you simply ignoreed all the references to The Rules when you signed up? Not good... :icon_rolleyes:

and
dont

return

from your

case

statement
why????

Because it's just as easy to exit the loop and let the real return take care of it. And it's bad programming practice... Ideally, functions should only return from one place. This is not a rule set in stone, but a guideline. It can't always be accomplished.


and please comment on the solution...

thanks & regards...

It works fine.

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

You seem to have been here long enough to know better than post a title like this. See the Rules.

In looking at your list of threads, STOP using noob/newbie/etc in the title!!! Just use a good name!!!!

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

Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it?

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

Since it helps to explain what is wrong instead of just tossing new unexplained code at you, here's what's wrong with your code:

my code:
#include<time.h>

int main()
{
// first of all, why isn't the following indented?
int num[50];
int x,odd,even;
srand(time(NULL));

for(x=0; x<50; x++)
{
         num[x] = (rand()%60)+40;
         
         }
         // second, why is all the following indented?
         for(x = 49; x>-1; x--)
         {
               if(num[x] % 1==0)    // x % 1 is ALWAYS 0.  Any number / 1 
                                    // has a remainder of 0.  You need 
                                    // x %2
               {
               num[x]=odd;          // 'odd' has no value, it never was 
                                    // set. Do you really want to 
                                    // replace the number with 'odd'?
               }
               if(num[x] % 2==0)    // This next section would be better 
                                    // served with an 'else'
               {
                         num[x] = even;
                         }
               
               printf("%d\n", odd);
               printf("%d\n", even);
               }
               getch();
               return;
               }

See this about code formatting. Also explain what you are trying to do. "sort" has many definitions, and although what you seem to be doing can be called a sort, it's not what we consider a sort.

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

You didn't look hard enough. Didn't you run across the getline() method?

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

plz comment...

OK, here goes:
1) No CODE tags -- they are mentioned in The Rules as well as all over the site. Even where you typed in your post.

2) English!!!!
i m -- I'm
u -- you
dont -- don't
plz -- please
also mentioned in The Rules. This is not a chat room.

3) Don't return from your case statement.

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

long int??? for what??? sorry i didnt get ur point..
i m using double to store the number of total permutation and an integer array[n] to store different permutations of n numbers...

Doubles are inexact. You can't have 2354.34 permutations. Therefore double is a bad choice.

And how will long int affect the running time of my program...

Floating point takes longer to compute. Granted in this program it may not make a noticeable difference...

also changing the memory model to large or huge...
i m using Dev-C++..where does this model means??? how to change it??

It doesn't. Jishnu obviously thinks you're using a very old compiler.

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

@scru
other than maybe spelling mistakes i dont see what i did wrong. computers remove from humans the need to consult dictionaries. unfortuanately that is not true on daniweb. anyway. that is redundend at this point. i was just pointing out that one could not readily understand what he meant. jasimp misunderstood him too. and many of you would have had i not figured out what he meant.

You seem to have a "don't give a damn" attitude.
1) Use a browser that highlights spelling errors. Mine (FireFox) flagged 3 above.
2) Sentences start with capital letters (A-Z) in English.
3) Contractions have apostrophes (won't, can't, you're)
:icon_wink:

>>spamming a forum
i dont see how advertising links in your signature counts as spam. i mean it does not harm anyone. and dani can claim a percentage of the profits and so it is a boon for her as well.

How can she claim a percentage?

I respect Daniweb's image of a not-for-profit community which consists of people giving their time freely because they enjoy it, rather than posting just to earn money.

"not-for-profit?" Somehow I don't think so. Dani has made it quite clear that this is not a non-profit site. The more traffic, the more she makes.

and even when he attempts to explain his insult he fails to make anyone see how it's insulting :)

I got it, without explanation :icon_twisted:

iamthwee commented: point's 1, 2 and 3 were priceless +13
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, please read this. Your titles are worthless as they are. This thread should be titled something like "Using user32.dll with Dev-C++"

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

Also, you don't have to announce you're a newbie with every thread title. Just title the questions with good titles like you have been doing.

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

So use cin.get() after a prompt that states "Press RETURN to end"

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

the only problem with this is that it hasn't been taught to us yet (the *number[] part)..
so we have to use only whatever has been taught to us
i tried using nested if's but all those {} are making me dizzy, i keep getting errors and i cant keep track of my variables..

Then you're probably not formatting them correctly... :icon_wink:

just got back from school..

So? :icon_razz:

i got the 10-19 part ok now.. before when i type 312 it says three hundred two but its fixed now..
the only problem left is that it wont display ones digits..
i've gone over reviewing this many times but i cant figure out whats wrong..

Again, look carefully at this piece of code -- before Nick Evan gets here and tells you what I mean :icon_twisted:

if (z < 10 || z >= 20)
   {x = z % 10;}
else if (x == 1)
   printf(" one");
else if (x == 2)
   printf(" two");
...

How does this code allow you to get to printf(" one") ?

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

And Walt, I am sorry if I don't know the proper etiquette for posting. I am learning.

All it takes is reading the Rules and the sticky posts at the top of the forum...

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

thanks for reply, it works fine but theres a couple more things:

1) how to i calculate the number of of comparisons made and then print it?

Set a value to 0 before the loops and increment it immediately before the comparison. When the loop is done, output it.

2)im am trying to output in the form

After pass 1: 2 4 6 8 10 12 45 37 68

instead i can only manage to get
After pass 1:
2 4 6 8 10 12 45 37 68

I want it as a single line output,. I have tried fiddling around with cout statement into one line but wouldn't work.

Don't output \n at the end of the statement.

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

You might also consider using arrays for your 'words'. It would make your code shorter. For example:

char *number[]= { "", "one", "two", "three", "four"... "nine"};
...
x = z % 10;
printf( " %s", number[x]);

You can do this for all your numbers, including the teens and 10-90.
The 'zero' is blank because you never really output 0 in word form.

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

(good guess, Walt, but it wasn't the problem in this case. I'd have thought the same thing.)

OK. I, like many others here, don't download links. The code must be posted. And preferably not 500 lines, just the section in question...

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

Look carefully at this section of your code:

if (x<10&&x>20)

x=z%10;
if (x==1)
   printf(" one");
...

You also might want to consider using more spaces in each line to make the code more readable. Something like:

z = num % 100;
if (z >= 20  &&  z < 30)
...
else if (z >= 40  &&  z < 50)
   printf( " forty");
else if (z >= 50  &&  z < 60)
   printf( " fifty");
else if (z >= 60  &&  z < 70)
   printf( " sixty");
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If the nodal name is a string type, you can simply add "_info.txt" to it to create the file name. Open and output the rest of the line. Close the file. Read the next nodal name.

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

Mr. Cool, what do you do when you have to run the program on a system that does not have the CLS operating system command?

Here at DaniWeb, we try to give help that doesn't rely on system-specific solutions. Solutions that can work for as many people as possible.

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

Without even looking I'll bet this will help -- feof() and .eof() are identical.

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

You can't compare the string player->GetGold with an integer. If that doesn't solve the problem, give us the information we need to understand the problem. Try reading the sticky posts at the top of the forum for some suggestions.

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

you mean in the old ancient Turbo C ? You can't. Get a newer compiler that supports such things.

Sure you can. What do you think they did way back then? Use a time machine to get today's compilers to read an image file? :icon_wink:

safira, depends on what you mean. Please explain in detail what you're trying to do.

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

Obviously you have NOT read the links I posted. If you want help, you must do what was suggested when help is given.

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

Have you read this or this yet?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int anyPositiveEOF (void)
{
	int anyPositive = 0;
	int numIn;
	int counter;
	for ( counter = 0; cin >> numIn; counter++ )
		if ( numIn > 0 )
			anyPositive += numIn;
		else
			return -1;
	return anyPositive / counter;
}

This what you mean?

How do you exit the loop when you don't want negative numbers?

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

In other words, the address from the new is loaded into pstr. This buffer is not local to the function, only pstr is local.
When you return, the variable pstr is destroyed, but the contents (the address of the new buffer) is returned. That buffer is not destroyed.

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

If you want to do that, do it. Output the loop index.

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

thank you for the advice. i got it working just fine now. still getting used to the mod function. never saw it before this semester. i used this code to get it to work for anyone else who happens to have a similar problem

if (num <= 5000) {
    th = num / 1000;
    h = (num / 100) %10;
    t = (num %100) / 10;
    o = num % 10;
    roman = roman + thousands[th] + hundreds[h] + tens[t] + ones[o];
  }

Sorry, but that's a convoluted mess.

How about something like:

if (num <= 5000) {
    th = num / 1000;
    num = num % 1000;  // get rid of the 1000s

    h = num % 100;
    num = num % 100;   // get rid of the 100s

    t = num / 10;
    o = num % 10;
    roman = roman + thousands[th] + hundreds[h] + tens[t] + ones[o];
  }
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I think Lerner is well aware of the problems associated with system("pause") .

Then he should know better.

I wouldn't say 'never' use it. Sometimes, it is more important for a newbie to just get their program working than having to worry about the difficulties of clearing the input streams.

I would. Aren't newbies taught cin ? If so, why teach them another command? One that's not a good command to use? I stand by my statement.

iamthwee commented: Congratulations, you have just been promoted to Captain Retard! +13
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My guess is that you are couting a variable that has yet to be initialised to some arbitary value.

Actually, you may be cout ing a variable that has an arbitrary value, and you should initialize it to a specific value.

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

To keep the window open after completing the program put in something like this on line 54:

...

system("PAUSE");

No. NEVER!!! :icon_rolleyes: Here's why!

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

Do the program in small steps:
1) Start by reading each question and all the answers into 6 strings. Continue until all questions read.
2) Next step, read as above and write all but your answer to the new file.
3) Third step, after reading, look at your answer and replace the correct letter with '*' before writing.

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

Rather than test each character with separate IFs, use a FOR loop.

And to test for a winner, just look a COUNT. If it's 4, you won. Simply break out of the loop. After the loop, check COUNT again. If it's 8, you lost, if it's not, you won. Don't print WIN or LOSE inside the loop. The loop should be only for checking the input.

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

Here I write some code for my task but it doesent work.
Please someone to chack my code and to correcte my code

No, you check your code. You tell us what it's doing wrong, and what you expected to happen instead. Also, point out where in the code you think the problem is. Then we will point out ways for you to correct the code.

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

Try using strstr() to search for the. Keep in mind that The and the are not the same because of the first letter.

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

First of all, your formatting is fairly good, just a tad inconsistent. Be a little more careful with your indentation.

The concept of mastermind is almost identical to the game Lingo if you get the cable station GSN (Game Show Network).

After the user enters his guess, you need to compare that guess character by character with the target "word". Tell that user
1) the number of letters that are correct AND in the correct postition
2) the number of letters that are correct but in the incorrect postition

Example:
Target adcd
Guess acdb
Result:
1 character correctly placed
2 characters incorrectly placed

A is of course in the correct position and CD are correct but in the wrong position.
The way I've done this is three loops.
Loop 1 to check for correct positions
Loop 2&3 are nested to check for the other letters that may be correct.

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

Not really a problem, but your prototypes don't need [4]. They can be specified as:

bool checkRows ( int theSquare[][], const int numRows, const int magicValue );
bool checkColumns ( int theSquare[][], int const numRows, const int magicValue);
bool checkDiagonals (int theSquare[][], const int numRows, const int magicValue);
bool checkRange ( int theSquare[][], const int numRows, const int magicValue);

In the checkRows() function itself, you can't use rowNum in the parameters. Since it's a 4x4, just say so:

bool checkRows ( int theSquare[4][4], const int numRows, const int magicValue )

That should help.

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

Narue, how can you put cplusplus sysntax highlighter in your post?

[code[B]=cplusplus[/B]]
[I]your code here[/I]
[/code]

Isn't that on the background of the textbox in which you entered the question?

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

My understanding re cin.clear() is that if the cin fails (eof or mismatch of data) then further access or use of cin is prevented; to avoid this use the clear() method.

True. So what error are you expecting that needs to be cleared at this point?

I guess you're probably suggesting that in this particular case it's not needed. Looking at the code I can't see how a mis-match of data cin >> ch could occur and I don't think EOF is an issue either. I hope I haven't embarrassed myself with this answer or response.

That's what I'm suggesting, yes. And you have definitely NOT embarrassed yourself. It's a correct analysis.

Taking this a step further in relation to cin.clear(). If the receiving variable is of a numeric type is that when cin.clear() would be considered in fixing up erroneous data entries.

Actually, no. All cin.clear() does is clear the error flags. If they were set, it does not fix any data entries. The way you're using it, the error is simply cleared and ignored. You never test for one, so you don't even know it happened.

What you suggested above is "If the receiving variable is of a numeric type" and you type in a letter instead, cin.clear() magically changes the letter to a digit. What in fact happens is the error flags are set, nothing is loaded into the variable (previous value remains unchanged), and the letter stays in the input stream for the …

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

Look at each number and save the highest number entered.

Did you miss reading the Rules?