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

Instead of using fgets() , use a FOR loop to read num numbers using scanf("%d"...) .

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

mdiParent.cmdPrint.disable -- specify the form.

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

Hi, guys I am working on vb project, which will save client database.

I've done the coding of ADD, NEW, SAVE, EDIT button. Now, I am stuck at DELETE button. When I delete any particular client then I want my client_id (it's a column in my access database) should get updated (like if I have five clients in database and if I delete 3rd client, then the client_id should start from 1,2,3,4; not like 1,2,4,5)

No it shouldn't. Once assigned, a client ID should never be changed. It is their unique value used throughout the system. All records pertaining to that person should be using this number and not their name, so the change would be monumental in a 'real' database.

What do you think would happen in the real world if, when someone stops driving, all the driver's license numbers changed?

Netcode commented: lol +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Never define variables in a header file (.h)
They go into source files (.c)

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

Then find a compiler that has documentation.

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

Because by definition and design of the language it is wrong. See this.

You must understand that just because something works fine does not mean it's correct. It is very possible to drive through a red light. It works. But various bad things could happen. And because the law says don't do it we don't do it.

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

Sounds like you might have your srand() call in the wrong place. It should be called only once a the start of main()

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

it is saying that "incompatible pointer conversion"

Oh goody, a guessing game! The odds: 1:139 chance of guessing the correct line.

See this and read it this time.

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

Use return 1; to indicate an error. return 0; indicates a successful execution.

All other values are not portable and may have no effect on many systems. I don't know if they'd be a problem, though.

On Windows, other values can be seen by the system and used. A batch file can get the exit status and process different code based on the value.

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

Also, have you ever heard of SPACEs? Your blob-of-text format is very difficult to read. Take this blob:

int month,mth,yr,cen,day, year,dow;
  string name;
  getInput(month,day,year);
  mth=getMonthValue(month, year);
  yr=getYearValue(year);
  cen=getCenturyValue(year);
  dow=(day+mth+yr+cen)%7;
  switch(dow)
  { case 0: name="Sunday";break;
    case 1: name="Monday";break;

(where'd that space come from at day, year ) :icon_wink:
Reformatted so it's readable:

int  month, mth, yr, cen, day, year, dow;
  string name;
  
  getInput (month, day, year);
  
  mth = getMonthValue(month, year);
  yr  = getYearValue(year);
  cen = getCenturyValue(year);
  dow = (day + mth + yr + cen) % 7;
  
  switch(dow)
  { 
    case 0: 
      name = "Sunday";
      break;
    case 1: 
      name = "Monday";
      break;

Try it. You'll like it. And so will your instructor.

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

getche() is a non-standard function and should not be used at all. They are trying to keep the program window open when you execute the code using the IDE. It's best to use a standard C function (like getchar() ) for that. return 0; is required because main() is an integer function. Any instructor that doesn't use return 0; is probably using void main() , which is wrong. Try not to take classes from these instructors -- they don't know the language well enough.

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

Use while (!myInfile1.eof()) in place of line 35 and also close file handler at line 70) myInfile1.close();

No, don't. Here's why ( feof() is the same as .eof()

Xaviorin commented: Great resource with thorough explanation +1
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

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

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

"...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

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

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

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

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

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

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

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

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.

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

Set up a while loop that finds the largest digit in num and creates sorted:

save num for later in numSave; set smallest to 10
Loop until num = 0
   get last digit (%)
   remove last digit (/)
   if digit > smallest, replace smallest

Now remove that digit:

copy numSave to num
zero numSave
loop until num = 0
   get last digit (%)
   remove last digit (/)
   if digit != smallest,  multipy numSave by 10 and add digit

Add smallest to sorted (properly).
If numSave != 0 Loop back to do this all again

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

Two possibilities:

Find the '.' and remove it. Reverse the number. Add the '.' back in.

Reverse the value. If the '.' is not in the proper position, switch characters until it's in the correct position. I.E., If your number reversed is
52.1232 switch the dot giving
521.232 and switch again
5212.32 and output the value.

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

30 minutes have passed so I could not edit my original. Sorry for the repost.

No need to apologize. We understand the forum limitations.

Hope this is more readable.

No, it's not.

It actually helps to read and understand the link given, not just make more stuff up.

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

Hey all,

I have a question how would I go about perform a comparion for two boxes. I would have to find the length, width, and height of both boxes and compare the volume of them to see which box would have be larger.

You've got the solution exactly...

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

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

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

Try outputting the words immediately after you input them.

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

It's because when you enter Y or y aren't you also pressing [enter]? You are leaving the [enter] in the buffer for the next input statement. You need to clear your buffer. I leave that exercise for you to search out.

A couple problems, though:
Never call srand() inside your program. Call it only once at the beginning of main() . You are seeding the random generator, not growing a forest of generators :icon_wink:

If you check if 'y' or 'Y' is entered, what are the possible values for the else condition? Is there really a need to test if the value is not 'y' or 'Y'?

Why are you calling play_game() then you have 2 WHILE loops to catch the result? Call the play_game() function only inside one single WHILE loop and use your YES choice to exit that loop. Your program will be much smaller and easier to follow. And you won't need all that IF nonsense at the end of the loop since the WHILE acts as an IF anyway.

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

Are you supposed to
A) input 10 numbers and not output duplicates?
B) input numbers until 10 numbers are output?
It's not quite clear.


Another option to each of the above is to set an array of 101 integers (0 to 100).
Zero them all.
As you read in a number, test array[number]. If zero, print it. If not, it's a duplicate.
Add 1 to array[number].
Go back and read another number.

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

Do not change j inside your loop.

All you need to do in the inner j loop is:
1) Compare b with the current x value (you are doing this)
2) If less than, replace b with the current x value.
That's it.

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

just use system("pause") in the end before return

Search for this terrible function call on this board and learn why we do not suggest it.

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

Then try reading the string twice. Once to clear the buffer, Again to actually read the input.

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

When you enter numbers (like your doubles) the ENTER is left in the input buffer, since it's not a number. You need to clear it before reading a string or a character. Look into the cin.ignore method.

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

Excellent!

Nicely formatted (up until main() )
Commented (could use a few more but much better than most code here)
No glaring use if undefined behavior
And no conio.h!! Yippee!!!

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

I can think of worse places to get stuck... :icon_twisted: