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

My most recurring problem is clicking on the UP/DOWN arrows and have nothing happen. Finally after multiple clicks, the box usually opens. But not always.

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

Of course there is. cin will accept all data types in one statement.

Maybe you need to explain in detail what you are trying to accomplish in the end. Based on your question as posted, it's a trivial procedure. Just look at one character at a time and combine them into separate strings based on operator/digits.

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

At least with GNU GCC, there is not need to reinvent the wheel, they are declare (very logically) in math.h: http://www.gnu.org/s/hello/manual/libc/Rounding-Functions.html. As that is standard header they could be even part of standard:
http://en.wikipedia.org/wiki/Math.h

Sure. And when you need to actually know how to do it because your next language doesn't have math.h, what do you do? People should not be relying on library functions for this easy stuff as a new student. They need to understand the underlying concepts first.

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

It's your thread. Mark it solved.

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

Add 0.05 before the truncation.

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

Does it bake cookies or cakes?

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

Allow me :icon_rolleyes:

Maybe you can learn something from this post...

Saith commented: Awesome :D +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just test the end of the string for 0x0A and replace it with 0x00. Then test again for 0x0D and replace with 0x00.

Unfortunately, this doesn't seem to work. I've tried this and various other combinations and I'm still stumped.

Then you probably did it wrong. Can't help if we can't see what you tried.

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

Or the browser BACK button? Or opening the link in a new TAB?

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

That's not broken English, that's leet, AFAICT

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

Last question, how do I know where to initialize the variables?

You initialize a variable where you require it to be a specific value.

In other words, why is delay = 0; initialized in "for-loop: i" rather than "for-loop: k"?

Study the loops. What happens if you initialize it in the K loop? Does the code still work? If not, that's not a good place.

You have to analyze the code to determine the best place.

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

Yes. And no. It depends. All you really need to understand is int delay; creates a variable with an unknown value. Don't use it without setting a value. int delay = 5; creates a variable with a known value. delay = 5; sets an already created variable with a known value.

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

Because you are using .eof to control your loop. See this. feof() is exactly the same.

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

Maybe changing from XCode is in order...

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

What does your error checking tell you of the open and write?

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

Just test the end of the string for 0x0A and replace it with 0x00. Then test again for 0x0D and replace with 0x00.

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

If \n is the EOL character, how can it not be the EOL character? "if '\n' is a legitimate part of the string data" is meaningless if it's defined as an EOL character. You need to decide how you define what. And since you didn't really answer my question, all I can say whatever you are doing must be wrong and I don't know what you ultimately want.

Your description makes cursory sense but when we get down to the little details, you try to describe (rather than show) in a confusing and detailless way what you want.

Ever hear the adage "a picture is worth a thousand words?"

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

That completely depends on what you really want the string to look like when you're done.
If your string is ABCDE\n98765\nalpha-omega\n , what do you want it to contain when done?

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

This leads me to thinking that maybe I can't just replace the "\r" and "\n" characters, but everything I read suggests that it's the combination of the two that Windows uses to represent EOL characters.

Correct...
Windows uses <CR><LF> combination
Mac uses <CR> alone
*nix uses <LF> alone

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

Without proper formatting, your code is extremely difficult to read. Repost with good indentation.

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

What if there are 2 or more spaces between some words?
Did you count the first word? It has no space in front of it.
Did you consider the way many people now incorrectly write? They never add a space after a sentence -- just run the 2 sentences together.

Things to think about.

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

I think my problem lies in the capital function(). Only the first line capitalizes. I have gotten it t work in using cout, but it doesn't update the saved file.

I am confused in using the ifstream & ofstream in the same file at the same time so maybe my logic in where I am placing the declarations is off. I just don't know! I just want it to work so that I can then add the error checking and format/tweak it.

Your technique for learning to program needs work. Your technique is to write the entire program and try to fix everything at once. A better technique is to write 1 single necessary piece, get it working, then add the next piece.

So, if you are having trouble understanding I/O, write only that piece.
1a) Read the file
1b) Display what was read and make sure it's correct.
Now move on.

2a) Add write the file
2b) Check the file and make sure it's correct.
Now move on.

3a) Add capitalize the date
3b) Display the new data and make sure it's correct
...


So I'd start again and take it a step at a time. Use what you have as a template.

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

Since you won't explain in why the link I posted is in error, I must assume it's correct, therefore Narue and I are correct, any you haven't learned enough C yet to know why you are not correct.

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

WaltP-I think so you need to study more ,understand the difference between preincrement and postincrement....
The link you gave is only for postincrement....
Better you must read it properly....

Really? Please explain exactly what and were my mistake was. Please go through that link I gave point by point and explain where I am wrong.

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

You see certain syntactical expressions have a higher level of precedence than others By this I mean certain codes are "more important and so are executed first...for example ++ has a higher level of precedence that just + and brackets,namely () have an even higher order of precedence than ++ so the code below is saying

int n1=2;
int n2=0;
n2= (++n1) + (++n1);

(reading from right to left; the same in this instance vice versa), increment n1(n1 everywhere in the program is equal to 2+1 which is 3..but brackets has a higher level of precedence than the + so n1 is incremented again, thus becoming 3+1=4 everywhere in the program...You now have simply 4+4 which is eight..Makes sense?

No. First of all, as a professional programmer, even I was confused by your description in the upper half of your post.

And in the lower half, there is no guarantee you are correct because n2= (++n1) + (++n1); invokes undefined behavior, as Narue tried to point out. See this.

So, you can't tell if the answer should be 6, 7, or 8.

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

Both are new... I'm sure an announcement is coming.

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

Check your braces carefully -- top to bottom.

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

@WaltP You're being very convoluted. I understand you're not obligated to help, but your replies are very obscuring. If you can point out the obvious, I'd just appreciate that more. Thanks for your previous replies.

Sorry. I was trying to get you to think through your problem, and try to debug what you started with. Since you didn't bother to try any of my suggestions, I'll back out.

Good luck.

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

Get a random number modulus 2 to get a bit.

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

You were closer before.

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

Why don't you actually look at the values as you calculate them -- just to see if your calculations are correct. Output them. I assume you know what DD:HH:MM:SS you are expecting from the seconds you enter, right?

Also, it might help to actually use pencil and paper to execute your code by hand. That's the best debugging you can do at this stage.

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

You need to think about what you are doing and look carefully at the variables you are using. Are they the correct variables for each line?

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

It also depends on the compiler, too. Most compilers can't do it.

In your case, I would guess it's VC++ something, so getch() would work.

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

What keys -- all of them -- are you hitting when you answer the question? Isn't it n[ENTER] ?
If so, your code reads the n , correct? What happens to the [ENTER] ? Well, the next input gets it and does what it's supposed to do. Exit.

You need to clear out the input buffer after reading the first character. There's a sticky at the top of the forum to explain how.

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

Ok, so I don't quite understand how the

srand()

function is used, (line 34 of main) in combination with the functions

rand()

line 48 and 49. Why do we need srand() in this program, isn't rand() enough?
thanks

See this and this

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

Ok worked out most of the bugs but now win I compile it I get an undefined symbol error.

(14) unixs1 $ cc keyword.c
Undefined first referenced
symbol in file
getch keyword.o
ungetch keyword.o
ld: fatal: Symbol referencing errors. No output written to a.out

And this is exactly why we recommend that you guys should not use compiler-specific non-standard functions when you code. Those functions listed do not exist in your compiler. But do people listen? Noooooooooooo.... :icon_twisted:

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

We have flag bad post. We have infractions. We have rep.

Maybe we need a button for whiner!

Steve Nelson commented: You should get one for your account +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Add a ; after your keytab structure.

On line 13 you don't have a type name (like int keytab[] )

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

You must first go without sleep for 36 hours before being subjected to numerous hard-hitting questions like 'What you did last Summer'...

But I already know what you did last summer! :icon_twisted:

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

Yes, but as already said, why? We don't really need more speeches. And it looks like you're posting just to post. That is frowned on.

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

Why can't you read the line into integer variables? Isn't that allowed?

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

I don't think anyone has noticed, but the assignment doesn't mention string nor character array anywhere. Where did you get the requirement to convert stuff to a string? Why not just read the values as integers and compare?

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

>>A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.


To clarify, you're saying...

for(int i = 0; i < 10; i++)
{
    // code
    i = /* whatever */  // <--- bad
    // code
}

Correct?

IMO, yes. Using the OP's question directly, the loop would be:

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) i = 11;
    // code Keep going
}

is better served by

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) break;
    // code Keep going
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

IMO, each member does not need to be welcomed. If they don't post in the introductions forum, it doesn't seem to be necessary.

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

In this case it's perfectly fine. You don't really have what's called a loop counter. You have variables that are tested in the while statement.

A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.

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

You can't define a function inside another function. Move it outside.

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

After you read an integer (12) you still have the ENTER in the buffer (you did press ENTER, didn't you?) After reading integers, you need to clear the input buffer before reading strings and characters.

There is a sticky post that discusses this at the top of the forum.

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

I don't see any attempt at trying to make a function. Give it a try, format your code, and repost with CODE tags so we can help you.

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

Look up the FORMAT function.