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

Yep. Just trying to make you think...

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

Start by formatting the code so we can follow it.

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

I've tried to use the toupper() in the sort area, but I'm getting a lot of weird errors, I think it's because all the strings are now in an array and my toupper is not working. Is there any other way to accomplish this?

Completely useless information.

First thing is stop ALL conversion. Do not use toupper() at all. Do not use tolower() at all. Get the program working with no conversions.

When you get that working, post code, explain what it's doing correctly (so far) and explain how you need it changed. With examples.

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

I may be repeating myself with this but what I THOUGHT

Customer.substr(currentcount,Customer.length()-currentcount+1);

meant was that after grabbing the string Customer:

Customer.length()-currentcount+1);

would take string Customer: "Bright, Rich, PC12K2RT, 10/21/2011" and remove the first value including the first comma and the next whitespace leaving "Rich, PC12K2RT, 10/21/2011"".

Then rinse and repeat until EOF

You are correct in assuming that it removes the first value, but you don't do anything with that changed string, therefore, you lost it. Just like the statement
customer - currentcount; correctly subtracts currentcount from customer, but the result is lost, since it isn't stored anywhere. You simply need to store the result:
whatever = Customer.substr(currentcount,Customer.length()-currentcount+1);

Xaviorin commented: put up with me for a long time... i appreciate it more then you know +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

also, I can understand what CODE is, but I don't think *anybody* has even a clue what ICODE means.

I do. And I use it correctly, and often, too... :icon_wink:

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

"...in the code i was using our teacher mentioned this snippet" implies you are in a class, presumably in school. Which means, usually, there is a textbook. Textbooks usually explain functions and methods being taught.

What does your textbook say about string methods, specifically substr() . Does simply calling substr() change the string? That looks like your assumption.

The rest of your post seems to imply you would rather spend hours looking at forums and web-based information rather than spend a few minutes looking at your book. Is that what's going on? In my experience, the book will describe what you want and give workable examples.

Especially when you say "I don't know how the function i am trying to use completely works." So look it up, and not on forums. Try your index. Google the function itself. Read sites that explain C++, not help sites, for (mostly) accurate information.


In looking at your code, rewriting this segment:

currentcount = Customer.find(",");
firstName = Customer.substr(0,currentcount);
cout << "\n\n" << firstName;
Customer.substr(currentcount,Customer.length()-currentcount+2);
cout << "\n\n" << Customer;

using simple integers rather than string(substr) you have:

currentcount = 200;
firstName = customer - currentcount;
cout << "\n\n" << firstName;
customer - currentcount;
cout << "\n\n" << Customer;

So what's wrong with this simpler code? What happens to customer?

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

I tried to. My question was meant to point you to a line of code that looks incomplete, to point you to what I think is wrong. Not for you to post silliness like "my brain hurts" and "i have no clue if an = is missing... i don't remember using one in school". If you've gotten this far in the language we know for a fact you've used an = at some time.

Now look at and analyze what you wrote, and what you're attempting to do. Look for errors in the line I posted that does not accomplish what you need.

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

What's useless about it?

No, the thread cannot be deleted.

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

It the Terra Nova colony messing with the time line...

jonsca commented: Okay, Captain Taylor... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Output the contents in a loop.

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

Do you know how to delete this thread?

Why?

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

This is just a little progress, I am trying to see if I am going about this properly....
Any advice as to how I should go about it?

1) Reread the link I posted more carefully and format your code consistently.

2) When asking for help, details are very important. You gave us only vague ideas of what might be wrong.

The answer to the non question:

For some reason the if statements are inconsistent, as well as the addition portion.

is "make them consistent" since we don't understand your use of the term consistent nor what makes you think they are wrong.

3) And the other non-question:

It is just a test algorithm to see if I did it properly and it appears not.

Answer: Oh? What makes you think so?

We can only help if you explain what help you need. Vague statements do not help us understand your problems.

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

the problem is this is not a string..
I just want a string for example :
I just want to entere 'ayam' not
a
y
a
m..
and the result should be 'maya'..
that's what i mean.

What is not a string? What is the definition of this?

Maybe you need to read up on what a string is and how to define it before you continue.

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

So what's the problem?

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

This has been reported in the Mod Forum.

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

Both issues can be solved at the same time by calling memset() to flood the array with '\0' bytes.

p  = malloc(n+1); // make room for null-terminating character
 memset(p,0,n+1); // initialize the array

or a simple loop for (i=0; i<n+1; i++) p[i] = 0; which is most likely something you already learned.

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

Oh so here's the assignment:
Write a program which sorts a list of words contained in a file alphabetically. Your program will sort these words alphabetically, and store the sorted list in a new file. You shouldn’t change the case of any of the letters involved.

See that last line? Do not change the letters. Period. Remove the line for(i=0; i<word.length(); i++) word.at(i)=tolower(word.at(i)); and think of another way to sort.
Like maybe use the toupper() in the sort area to compare but not change the characters.

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

So far, so good. You might want to format your code so we can read it easier next time you post.

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

Looks like an interesting project. Good luck.

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

What are you attempting to do with Customer.substr(currentcount,Customer.length()-currentcount+1); ?
It looks like you get the substring but you don't do anything with it.
Is there an = missing?

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

Hello guyz how r u all

Annoyed at people that use leet speek on a professional programming forum, which is against the rules.

i m new in programming

So? We all were.

can u help me plzz

You must be a certain age to be a member here, and this kiddie speak doesn't bode well. So maybe not.

can u tell me that how to arrange array elements in ascending in descending order in C++
e.g suppose we have an array of 6 elements.. let elements are 65289...i want to arrange them in ascending like 25689.... can anyone help me plzz.. its urgent.. thank u

Ahhh, and another urgent request with a do-it-for-me attitude. Read the member rules NOW!

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

Guys, I'm actually almost done. Basically what I have to do is to read from file with a list of words, sort them alphabetically and write them into another file.

Sounds good so far.

I am almost done, but the only thing is, the assignment says that we shouldn't change the case of words,

So don't change the case.

but I am changing everything to lowercase, ...

So don't.

...because I'm using arrays to compare letters.

Why does that necessitate changing the case?

Either you are under a misconception vis-a-vis the assignment
or
You haven't given us the entire picture vis-a-vis upper/lower case

Side thought --
When you compare, why not just compare the lower case values using tolower() ?

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

Help with what? A description of the problem isn't a question.

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 [i]you[/i] missed:
[list=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
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- 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
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]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?
[*]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.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hey guys ,
plzz help modify my code..

I don't see anywhere where you

use comments on your codes for us to check properly what your doing

If you are getting suggestions, I would suggest you don't ignore them. It just tells us all you want us to do is give you a working program.

Try outputting values at key points in your program to see what your program is actually doing. If the values aren't what you expect, you know what part of the code to look at.

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

Perhaps I should have thought it out anyways.

That's usually the best solution when learning. You remember more after figuring out a solution rather than letting someone else give it to you.

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

Why are you reading an int (ch) and testing as a character? It should be defined as a char.

What does letters do in your code if you increment it then immediately set it to 0?

Also see this ( feof() is identical to .eof() )
and this
and this

EDIT: I think I know where the problem lies: you need to use in.get() rather than the << operator to read in the characters. Here's a modified version of your code that ought to work correctly:

Come on, you know better than this...
And you are also wrong. >> works just fine.

Schol-R-LEA commented: I completely missed that! Thank you, that explains a lot. +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

YAY!!!!

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 [i]you[/i] missed:
[list=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
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- 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
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]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?
[*]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.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
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 [i]you[/i] missed:
[list=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
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- 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
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]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?
[*]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.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This loop is giving me ridiculous output, and the one a post above is only working when my number is in the format xxx.xx

*sigh* Why can't you follow simple instructions?

for(int i = balance.length()-1; i>=0; i--) // OPEN OUTER LOOP
         {
            
            if (i==2)
            {
                outFile << balance[i]; //// where is this statement in my 
                                       //// instructions if [B]i=2[/B]?  And is [B]i=2[/B] 
                                       //// the correct test?  Does it give 2 
                                       //// decimal places or 3?
                outFile << '.';
            }
            if (balance[i]!='.')
            {
                outFile << balance[i];
            }
         }                                       //CLOSING OUTER FOR

It's damn close. You just added stuff I didn't have. And you didn't bother to actually think about the condition.


Then there's:

for(int i = balance.length()-1; i>=0; i--) // OPEN OUTER LOOP
         {
            int a = balance.length()-1;
            if (balance[i]=='.')
                {
                    i--;                   /// where is this statement in my instructions?

                    ///  Is any of this code in my instructions if the character is a '.'
                    outFile << balance[i]; 
                    if (i==2) 
                    outFile << '.';
                }
            else   /// There is no ELSE in my instructions
                {
                    outFile << balance[i];
                }
 
         }                                       //CLOSING OUTER FOR
         outFile << endl;

This isn't even an attempt at my easy solution...


Why do you have to make my simple instructions so complicated?

for(int i = balance.length()-1; i>=0; i--)
    {
        If i = x then  // x is the magic number representing 2 characters left
        {
            output the '.' 
        }
        If balance[i] is not '.'
        {
            output balance[i] …
Assassin7893 commented: awesome +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When people here in forum can't understand what you are saying, it's your problem. Please make your points more clear....Don't make it feel like a insult.....:P

You're right.
Here's exactly what I said:

Advice #1: Reformat so the code is readable. Your indenting makes the code unreadable. See this.

How can I make it clearer? Please teach me...

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

What am I missing here?

2/3rds of my algorithm.

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

A letter is just an integer value. 41 = '1', 65 = 'A', 97 = 'a'. It all depends how you display the value, as a character or as an integer.

1) Do not edit a post after someone responds to it. It makes their response seem wrong.
2) fflush(stdin) is wrong -- see this

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

ok, i'm completely lost right now. My loops either change everything after the decimal to the decimal points, or insert extra numbers in between, or replace the point with a number, but i just can't move the point itself, must have written like 50 loops by now.


Look at my post and READ the code segment!
Follow it exactly!
Change nothing!
Add nothing!
Do not add any shifts! Do not add any if (something-3) tests!

I gave you EXACTLY the algorithm you need. Exactly!

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 [i]you[/i] missed:
[list=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
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- 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
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]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?
[*]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.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use google. Find out how a trig function is calculated in the real world. Then once you find that, convert the equation into code.

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

Yes, a 'string' already is a character array -- by definition.

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 [i]you[/i] missed:
[list=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
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- 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
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]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?
[*]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.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your C syntax is completely wrong.
Nowhere in your code do you even attempt to find the 2 highest marks.

So, no, you have not done it right.

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

Read the entire line as a string and look at the input character by character.

You post your code that shows your attempt and explains what happened. Then we will help you make corrections.

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

plz see if my validRook algorithm is correct

It helps if your ask a specific question about your code that we can answer. Just asking us to check if your algorithm is correct by reading code is difficult -- at least from a beginner's code. It's best to
1) explain your algorithm first, so we can check it.
2) post the code that executes the algorithm, we now know what to look for.

And your code is very difficult to follow because of inconsistent indentation. See this to help with your formatting.

plz ask questions to clarify yourself and also ignore the other functions for movement of other pieces ,they are commented

Rather than forcing us to search through your entire program, why not post the code you have questions about? Posting all the code at the end of your post is OK (it gives us an overall idea of what you are doing) but also post the specific code first so we can zero in on the question you have.

While you're at it, see this, too.

And rework your code into a loop so you can get rid of the dreaded goto statements. You should not use them at all.

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

OK, OK. Here's what I'm trying to get you to realize.
1) A dollar amount ALWAYS has 2 decimal places. (This comment is based on your misunderstanding of my previous post.)
2) To reverse the balance using your loop definition (with 1 minor change)

for(int i = balance.length()[B]-1[/B]; i>=0; i--)
    {
        If [B]i[/B] (the loop counter) indicates there are only 2 digits left in your balance value
            output the '.' (you are at the cents portion)
        If the current [B]balance[/B] character is not a '.'
            output the current [B]balance[/B] character (but [B]not[/B] the '.' from the balance value)
    }

Now look back at my posts. Do they make any sense now?

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

I'm not sure what you mean by "make more stuff up". What exactly am I making up?

I gave you a link to explain how to format your code. You ignored it and reformatted in a completely useless way. I posted the link for you to learn from.

I would appreciate the constructive criticism alone, without the senseless, arrogant insult.

It wasn't an insult. And I gave you constructive criticism and you ignored the help.

And about your code, well you should indent it correctly.....

Gee, isn't this exactly what I said? And at least I included a link to explain how! Your comment didn't help at all... But then, I notice, that's your way.

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

My questions were there to help you answer your question, not explain the loop to us.

And yea, i can be 2, it's the string length.

and where does the period go? In the 6th position? The 3rd? Or...?

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

But the thing is it's not just two digits left. It could be 3 or 4 digits left, based on the file.
123.1 would become 132.1
12.136 would be 63.121
14.2 would be 24.1

So?

What is this loop supposed to do?

for(int i = balance.length(); i!=0; i--)
         {
//This part deletes the decimal point and reverses the number, it also shows the location of the decimal
//******************************************************************************    
            if (balance[i-1] == '.')
            {
                int a = i;
                balance[i-1] = balance[i];
                i--;
                cout << "The position of the decimal point is " << a << endl;
            }
//******************************************************************************         
            outFile << balance[i-1];
         }

And what is i? Is it ever equal to 2?

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

Usually this error means you have mismatched braces. Check you braces very carefully.

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

Too complicated.

During your loop,
1) If you see the '.' just don't output it
2) When you have 2 characters (digits) left, output a '.'

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

srand() must be called only once -- at the beginning of the program.