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

You said the code isn't designed to work, were you referring to the code i originally posted? Or to sundips code?

Sundips. Didn't you bother reading my post between his code and your attempt? I explained exactly what was wrong with his code.

The maximize size the file can be is 60kb. And no more than 20 lines.

To test the 1st character, read the first line. Test for and ignore all initial SPACES. If the first non-SPACE is a digit, you're OK, otherwise a bad file.
To test the last character, read the rest of the file. When you get to EOF, test the last characters in your buffer for whitespace (which includes the \n) which you skip. The first non-whitespace character also needs to be a digit, otherwise the file is bad.

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

Can anyone tell me what I did wrong?

Using code that obviously isn't designed to work, as I stated already.

You are making this much more complicated than it has to be.

How large do you expect the file to be? (maximum)
How many lines are you expecting to have? (maximum)

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

Then hide the quick-reply on threads that are older than N days.

And from the standpoint of "significant number", as far as mods are concerned, yes.
And from the standpoint of "other forums", who cares. We are not "other forums". We are allowed to be better than them.

I worked with a warehouse storage system which guaranteed no more than 1% misstored (lost) merchandise. Sounds insignificant. When you calculated that 1% it came out to hundreds of pallets of merchandise. No longer insignificant.

mitrmkar commented: Very good point on"other forums". +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
char firstChar[256];
size_t chars_read= 0; 
int currentLocation = 0;

while (input.good())
{
  nextChar = (char) input.get();
  firstChar[chars_read++]=(char)input.get();
}

So now in the firstChar[] array you have every other (even numbered) characters from the file. 1st, 3rd, 5th ... characters are not in the array. And this is supposed to help how?

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

What ^he^ said...

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

Forget the vector. Just
1) Create a string array with all the names in it.
2) Use srand() once to initialize the random function.
3) call rand() to get your random number x from 0 to 3
4) Display the xth name from the array.

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

sizeof() returns a binary value. Decimal and Hexadecimal are simply display values of those binary values to the user. If you see hex values it's because your cout has been told to display the value as hex.

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

Reread what Adak posted.

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

Not a clue what you are talking about.

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

Then read the entire document ( read() ), remove all \n's and search.

You can't find words that are split on a line without some kind of hurdle.

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

I see no hurdles mentioned and no reason not to use fgets() in any posts. Care to elaborate?

No one has offered this suggestion:
1) read a line with fgets() 2) use strstr() to find your word
3) check the character before the word and if it's an alpha character, it's not your word.
4) check the character after the word and if it's an alpha character, it's not your word.

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

That's like asking what are the advantages of Apples over Video Games. They are two different things.

jnawrocki commented: why bother -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then it's better not to use fgets at all.

Why?

I think it's okay to read " char by char " than to go through all the hurdles
using fgets.

What hurdles?

What is the difference between reading character by character

while((chr=fgetc(txt_file))!=EOF )
    {
        word[i]= chr;
        i++;
        ...
    }

and reading a line at a time

fgets(buf, len, txt_file);
    idx = 0;
    while(buf[idx])
    {
        word[i]= buf[idx];
        i++;
        ...
        idx++;
    }

The fgets() code should be faster and conceptually no different.

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

Usually command line arguments are meant to pass data into the program, such as
- a file name
- switches that modify execution in some way
- specifying the exact data to be worked on

Config files 'define' the environment for the program. Such as changing the program's default values to user defined values that are set each time the program runs. For example
- folders there data can be found. Define your own folders rather than using the folders the programmer set up.
- Set default parameters to your defaults rather than the programmer's
Things like that.

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

Oh I see, but it would work on Windows and Linux for his code and I doubt his O/S is set to delete his files

No, it will work on either Windows or Linux, not both. And how many O/S's are there? Can you be absolutely certain clear doesn't delete files on every one of them?

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

I actually made a mistake, I meant to say system("cls"), this is for windows as i assumed he is using that, system("clear") on the other hand is for Linux and it always works.

And you've just explained non-portable perfectly. It won't work on all systems without modifying the code, therefore it's not portable.

And I'm not sure what you mean by it will delete all the files.

The read carefully what I wrote:

And if you have an O/S that has defined clear to be delete all files, you've just destroyed a lot of work.

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

is this correct? because when I put my choice in, like for example I entered choice 1, it will just output the information that I putted in the case infinitely.

Then no it's not correct.

All your answers are contained in the responses you've been given. You just have to read *all* the posts.

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

How do you mean not portable?

It will not work on most operating systems. Linux/Unix for one. how do you know it will work on his O/S? He didn't tell you what he's using.

And if you have an O/S that has defined clear to be delete all files, you've just destroyed a lot of work.

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

You can also use

system("clear")

to avoid flooding the screen and to start afresh every time you loop

Bad idea. It's not portable. It calls the O/S unnecessarily.

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

2 comments:
1) while (true) is a terrible solution as you have no way to exit.

2) This is a perfect project to start learning how to read files. Each name and his information can go into a text file and you can
a) read the data from the file
b) populate a string array of names to output in a loop for the menu
c) populate a string array of information that can be output for the chosen name.

That way you can write the code generically, and the file is all that needs to change when you want to update information. As it is, the code is so larger it's cumbersome, and if you need to make a change to some data, you must recompile the whole thing.

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

How about choice != 0 ? Why a number like -999?

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

Your calculator seems to be extremely complex for the task as stated.

if minutes > 0 then hours++    ; If "part thereof", add 1 to hours
subtract minhours from hours   ; calculate hours over minimum
charge = mincharge + (hours * hourlycharge)
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Note:Toggle plain text and copy it somewhere else If it's too hard to read due to indention.

Note2: Then don't post poorly indented code. Use 4 SPACEs instead of TABs and indent correctly.

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

You obviously ignored every reference to CODE tags all over the place. Even the one that smacks you in the face when you type in your messages!

I also see no attempt at all to test if a number is palindromic. Since prime and palindrome have nothing to do with each other, you have not even made an attempt. Please reread the Member Rules.

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

Give it a try and post your attempt (with more details) and we can help.

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

Why did you remove all the while keywords in the second post?

Back to your 1st post:

I have some menu problems. So this is my first time, and I need someone to please solve the problem for me.

We don't solve things for you. We help you solve them yourself.

I need someone to please solve the problem for me.
Could someone help me. Get rid of this problem. Please someone help me.
== code ==
Could someone help me. Get rid of this problem.

4 times is begging. And if you think about it, isn't posting "HELP" on a help board redundant?


Why did you copy your program into the default case of the first switch? Just let the default go without changing gameOn -- two lines. And what's with that last while() loop that does nothing?

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

Isn't this kind of what our IRC is about?

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

i thought that maybe there was a way to read it as a string skipping the hyphens then converting it to an integer which is what i tried to do above but can't get it right

Not really, but you can read as a string and remove the hyphens, as Adak mentioned.

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

Hello..
I searched the forum for a thread that explains how to rename your username, but I couldn't find any.. How can I assign a new name to my membership here?
Thank you.

And you didn't find one thread titled something like "Please change my username?" You certainly didn't look hard.

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

I am trying to take a user input phone number and perform calculations on it as an integer of type long long.

Why? To see if the phone number is prime? This makes no sense because a phone number isn't a number, per se.

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

1) Start letter at 'a'
2) Start the do-while loop
3) IF letter is not vowel
4) output the letter
5) increment the letter
6) end of do-while if letter >= 'z'

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

My apologies but that's the way I felt on his reaction :)

Sorry....

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

What's strange in it?

Us. :icon_mrgreen:

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

Well I thought making this rule would encourage other users to post more and be more active on DW. Does it make sense now?

No. How would it encourage more activity? If I want to have my user name changed one of two things will happen:
1) If I have to make 48 more posts, I will go elsewhere and forget DaniWeb.
2) If I have to make 48 more posts, I will post 48 lame-assed posts anywhere I can just to get my 50.

Alternatively, I all I have to do is ask, I would think "Gee, this is a nice place, they are helpful. I'll stay around and become part of this community."

jonsca commented: Only 47 more to go! Just kidding, WaltP, but that was too easy. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Count the wins and losses. The one with the higher win count wins.

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

I've seen some posts of users changing their usernames. But some of them are like below 50 posts.

So? What's the problem?

I mean why would they want to change their Usernames if they've just have less than 50 posts?

Because they decided they don't like their member name after 5 posts?

I mean they could have just make another account.

And you're suggesting that a bogus member be kept around simply because they can't have their name changed?

IMO, no member needs more than one account except a few top-level members.
No rank-and-file needs more than one. It has caused problems when they do. And what would a second account be used for? What do you suggest we do with the first account?

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

4. How does it happen that people here misunderstand each other frequently?

We do it frequently for some serious fun and to confuse others.

Now I'm confused :confused:

Me too :D

See? It works!

You're not going to turn in yet another internetstalker, right? ("ohmygod, it's a woman on the interwebz!!"). Anyway, here's some global info about Daniweb and Dani.

See? That's what I mean by misunderstanding!!
So what if it's a woman?? I knew she's a woman (as appears on her image) from the very beginning, but I only thought she was a moderator.. That's the whole idea.
I dislike it to judge others quickly! I'm innocent :D
Anyway, thanks for the information.

A perfect example of misunderstanding. What Nick Evan said was a joke. It was "tongue-in-cheek" (look it up). The appropriate response would be "LOL! No, but I hear your sister is cute."

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

i always include the stdafx.h, otherwise i get reminded to do so.

By whom? I have *never* used it and my code works fine.

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

(sorry for the lack of braces, I tried getting rid of some for less confusion. Didn't think it would work but thought I might as well try :D)

1) Don't apologize, fix it. Add braces and you won't be sorry.
2) Removing braces makes the code confusing.
3) So put them back and repost.

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

I get no errors when I compile --- at least after removing StdAfx.h header.

What compiler? What O/S?

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

it is still not working. Any suggestions on what I did wrong? :| I can compile it but the results are the same.

Are you kidding with this? Can't you figure out a better, more readable way to accomplish this?

{
if (a==b||a==c||a==d||b==c||b==d||c==d);
                                       ^ what does this do?
printf("same letter \n");
if(a!='a'||b!='a'||c!='a'||d!='a'||a!='b'||
   b!='b'||c!='b'||d!='b'||a!='c'||b!='c'||
   c!='c'||d!='c'||a!='d'||b!='d'||c!='d'||
   d!='d'||a!='e'||b!='e'||c!='e'||d!='e'||
   a!='g'||b!='g'||c!='g'||d!='g'||a!='l'||
   b!='l'||c!='l'||d!='l'||a!='m'||b!='m'||
   c!='m'||d!='m'||a!='p'||b!='p'||c!='p'||
   d!='p'||a!='r'||b!='r'||c!='r'||d!='r'||
   a!='s'||b!='s'||c!='s'||d!='s'||a!='t'||
   b!='t'||c!='t'||d!='t');
                          ^ what does this do?
printf("wrong letter \n");
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

if (a==a||b==b||c==c||d==d) When is the variable a ever not equal to the variable a?
When is the variable b ever not equal to the variable b?
When is the variable c ever not equal to the variable c?
When is the variable d ever not equal to the variable d? else if(a&&b&&c&&d != 'a','b','c','d','e','g','l','m','p','r','s','t'); Look up the syntax for the IF statement.

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

Compare them one by one. Count how many times there is a mismatch. If it's two or less, there's only one different value.

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

I don't see any down-reps for you in the past month. All + rep back to June 10, where you must have been doing something people didn't like.

On the other hand you have been giving bad rep to a bunch of members in a Geek's Lounge thread.

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

what is the matter with this code?

For one, it's a bad title for a thread.
For two, no CODE Tags.
For three, bad formatting.
Four, old code practices from the 1980's.

First things first.
1) Read the Member Rules. Make an effective title for your thread.
2) Code Tags are described all over the site. Find them. Read them.
3 & 4) See this, this, this, and this.

The first error is a "declaration syntax error"

Given 53 lines, does this error as it is make sense?

The second says"declaration is not allowed here".

Where's here? If you were given this information -- and only this information -- what could you do with it?

Salem commented: 4 excellent points +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Sodabread commented: I like your answer better. +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I wrote two programs, but I'm in dire need of the third and be honest with you I could not at all to write the third program

1) Learn to format your code so it can be read and followed easily
2) See this
3) We won't write it for you. Most of us don't need the grade.

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

cout is the easiest debugging tool you have.

You suspect the file is not being read? After the open, display the status of the open -- did it work? After each read, display the data read -- is it correct?

You suspect u and uc don't work? Display values before and after IF's to see if they worked properly. Display messages to follow the flow of the program.

In other words, follow the program by outputting key data and positional statements.