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

As you know,
1) To check if the integer is a palindrome, you need to look at individual digits.
2) And you already know how to check if a string is a palindrome.
3) Also, isn't a string just a character array?

Armed with this info, break the integer into an array of digits (ints) using that % / stuff:

i=0;
while num < 0
    digits(i++) = num % 10
    num /= 10

Now check if the digits array is a palindrome.

Yes, the digits array will be in reversed order, but when checking for a palindrome it doesn't matter.

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

1) There is no input that tells the program if the guess is low nor high.
2) there is no attempt to change the bounds if the guess is high or low.

You need to at least attempt to solve the problem to get help. As it is we cannot help you correct what's not there.

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

You only need 1 loop. It is used to look at each character up to the ending \0.
In the loop you need
1) test for "
2) test for flag
3) convert char to upper IF appropriate

Now, look again at expanding this to further detail at your desk. For example, what's supposed to happen when step 1 is TRUE?

Also decide when you need to print. Each and every character? Once when the string is finished?

And when your written steps actually work (what you posted obviously doesn't) then and only then do you write the code.

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

Good idea. And rather than "trying to change this and that", take out paper and pencil and design what you need. Thinking through the problem is what you need to do, and plan the code.

The best thing a new programmer can do is run through the problem on paper as is you are the computer. This way you understand all aspects of the problem and coding becomes much easier.

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

Why is your IF statement outside to loop? All you are doing is testing if the first character is a ".

Then in the the loop you never even consult your flag. How do you know whether the character should be changed?

And please be more careful on your formatting. Consistent formatting is a must in programming.

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

You can't compare a single character ( szSentance[i] ) with a string " \" " ), especially a 3 character string. Single quotes represent a character: '"'

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

I don't know what your reduce is attempting to do, but it doesn't even attempt to get factors -- unless I don't understand the algorithm you're using.

Write down (don't code) the process you use to reduce a number into it's factors, in minute detail. When you get it into it's most basic steps, turn it into code at that time. I'd recommend turning the factoring into a function and have it return all the factors (array) of one number.

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

I know how to find factors of a number, I just need to figure out how to do it in a C++ function.

Yes you do. Or are you expecting us to do it for you?

You have to show us an attempt, then we can help you fix it if it doesn't work properly.

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

bool u = false;

So u is your flag. good start.

look at each charater.....

i'm not sure how to look at the characters in the array ...

You don't? What does c=szSentance[i]; do in the code you posted?

...and then set a flag to true
can you please elaborate a little on this.

Try an IF statement.

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

Look at each character. Increment a value when you see @. When done, if the value is 1 you're goo, otherwise bad.

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

You need to find the factors of each number.

This is also helpful.

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

Set a variable to FALSE - this value will keep track of "
Look at each character.
When you see a ", set the flag to TRUE
When you see a another ", set the flag to FALSE

As you look at each character, if the flag is TRUE, set the character to upper case.

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

Yes, %c should be used instead of %s. This isn't technically a C-string, just a simple array. A string would require 7 spaces, to accommodate for the NULL value at the end.

No, technically it is a C-string. It has quotes which by definition ends in a NULL value. The definition actually overflows the array.

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

I guess the terminology has changed, then. For the past 35 years initializing a variable has been setting it to a know value just before entering a piece of code (like a loop) that does some kind of processing. When did that change?

What you call initializing I always called defining.

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

you dont have to be such a <SNIPPED>. i got count working without your help why are you here? isnt this supposed to be a forum to help people? the only useful peice of information i obtained was what gerard said here:

And you still got it wrong: char list[9][31];

all i was doing wrong was not setting the count to 0 after each pass, an easy fix, if i can see that and you cant maybe im a better programmer than you

As I said, I couldn't read your code because of the formatting. Still can't.

Because I have no idea what you know, I was justified in asking. I'll remember not to offer help next time since you take offense at it.

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

This is not beyond his level. There is no reason to learn arrays before vectors. Novices should learn vectors because they convey the same concept but are "easier" and THEN be told that if they want to get rid of the overhead they can access the memory directly using arrays.

Of course there is a reason to learn arrays before vectors. It's what the instructor teaches. Plus, they allow concepts to be taught that vectors cannot teach.

No instructor I know teaches vectors first. If you feel they are wrong, discuss it with the instructor. But if they haven't taught vectors, the students can't use them. And how does using std::sort() teach the intricacies of sorting? Do you really believe the task to just sort, and not to learn anything about sorting?

:icon_rolleyes:

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

electro account[0].balance_due=$ 120.52; $ 120.52 is not a floating point value. The $ is an invalid digit. electro account[0].address[50]={Cane Gardens}; {Cane Gardens} is not a character array. Character arrays are designated "like this" (in quotes).

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

i apologize ive only been working with c++ for a couple months...

Really? You aren't a seasoned professional? :icon_twisted:
Naturally we can tell. It's obvious...

do you at least understand what im trying to do?

Of course. You want to sort strings. Nothing complicated about understanding. Doing is a little more complicated though.

how exactly should the count work then or is there a better way to do this that im just not seeing?

You don't want to count anything. You want to find two strings that need to be switched and switch them.

What sort are you trying to implement? Do you know how a sort works? I think you need to read up on the concept so you know the basic ideas you need to implement.

And heed what gerard4143 said. He's correct.

beejay321 commented: no need to be rude, im a begginer and he cant appreciate that +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Better yet, just add oldTimePtr.tm_hour = 0; since that's the only value you're missing. It's more explicit.

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

You can't initialise anything that has already been declared. You can only initialise something at the time it is created, after that it becomes assignment.

Not true. By setting a value, (for example- a loop counter before a while loop) is initializing the value.

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

They are backup files, generated when you edit your source file. Every time you save a file, the original file before the edit were made is renamed .BAK so if you made a mistake you can 'undo' your errors and start again.

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

unfourtantly i dont have a clue what this is and i doubt i could even use it as we havent been taught it yet in my CMPT103 class, ill see if i can figure it out and run it by my instructor before its due and see if i can get away with it, id just like to know why the windows freezing

Ov course you don't, but many people here feel that vectors are the only solution to using arrays. They love suggesting things obviously beyond your level.

Problem 1 is your formatting. Please format your code so we can read it easier. We can't tell your program structure the way you have it. This is something that for some reason instructors seem to think is unnecessary. It isn't.

Based on what I can see, your value count does nothing useful, and definitely not what you think it's doing. Rethink your sort -- it is not a sort, it's just a string mover.

Go through your code by hand and you'll see what I mean.

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

Did you try outputting the two values (oldTime/currentTime) to see if they hold data that looks correct?

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

Look up the mid function and put it in a loop.

thank you for the reply...but what is the function to detect the space when i used the mid function?

If you look up the function, I'm sure you can figure it out.

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

I respect your response and all, but I was just trying to explain as detailed as possible what I needed to do.

Cool

Your answer to my last question leaves me without a clue of what to code,

Do you know how to switch the gpa values if they are in the wrong order? The way you asked it seemed yes.

and what do you mean by "thats easier and faster than posting on a forum"?

You asked if the code will do something specific 10 hours ago. If you actually ran the code then, you would have had the answer 10 hours ago rather than waiting for us.

When I try and do:

in >> student >> studentGPA;

I am getting an error "no operator ">>" matches these operands.

How did you define in ?

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

Look up the mid function and put it in a loop.

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

doesn't this version of the program add the numbers, and their digits, correctly only if the arrays are the same size, that is, consisting of the same number of digits? Since, I'm thinking the array fills from 0 to SIZE, which is done left to right, as entered. So I guess what i'm saying is it's adding left to right, according to the array entry, and not right to left which is the correct method for summing. A consists of 12345 and B is 678, wouldn't the result, according to the way the arrays are filled up and added column-by-column, be 80145, since it's filling the en-entered B[3] and B[4] with zeros, hence the addition it sees is 12345+67800=80145, and not the intended 12345+678=13023. Just a thought...

As a programmer, write the program to correct for this. Once entered, adjust the numbers to the right in the arrays.

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

I quoted the wrong part of your post. Sorry. I meant

I tried it and it works fine if the control is a textbox although as mentioned earlier, it will execute the code under Form_KeyDown and then reflect what was pressed in the textbox.

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

Why do you want to programatically move the mouse? Just call the mouse click events directly with the proper parameters.

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

I have a question about:
infile >> names >> grade ;

Will this go through the first line of the file and put the name in names[] and the gpa in grade[], then repeat with i++?

What happened when you tried it? That's easier and faster than posting on a forum.

After this part, I need to order the array so that it is in ascending order, meaning that the lowest gpa goes first with the correct name, followed by the 2nd lowest gpa with the correct name, ect.

That's called a sort. You won't confuse us by using the proper terms.

I have to swap gpa[0] and gpa[2], which means doing the same thing to names[0] and names [2]. How do I make a swap?

By swapping both gpa and names when the gpa is in the wrong order.

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

Please help and before you post telling me to us "cout<<" and all of the things related to iostream or whatnot im not able to because of the older versions of c++ we use.

Then you are writing C, not C++. There is no C++ compiler that cannot use cout . It's part of the language.

And if you aren't allowed to use "iostream or whatnot", why are you including it?

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

Always nice to save a line of code!

Not always -- not if it makes the code harder to read.

for(unsigned j = 0; j < 256; j++)
    argument[j] = '\0';

is far superior to

memset(argument,'\0',256);

The former shows exactly what's going on in the context of the program.

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

So far, I'm confused by your English language descriptions of the problem:

My guess is we won't get a better description. I already asked for one and was completely ignored.

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

How does MySQL sort a text file, and why would someone use it for this type of sort?

And what makes you think this is a real problem? Isn't it more likely a hypothetical question to teach a student how to solve a problem?

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

As for the web browser which is the important thing, it does not work. The Form_KeyDown events do not get executed. :(

Did you see my earlier post?

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

Use CODE Tags -- they are described all over this site. Including on the background of the box in which you typed your question.

Please read the following information:
formatting
void main()
pausing a program

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

Sort in chunks, then merge.

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

Formatting!!!!!! Please!!!!!

for(int i = 0; i < length; i++)
  {
     if(origWord[i] = letter[0])  // Is = the proper comparison operator?  Look carefully
     {
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Would you mind defining what "doesn't work" means? Don't know whether that means it doesn't compile, displays the wrong numbers, causes a citywide blackout.

Details. Exactly what does it do, and what were you expecting?

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

No, do not use getch() . That is a non-standard C function (not even C++) in only a couple compilers. Use gerard's solution.

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

When you find an ad that does this type of thing, do you remove the ad as a violation until fixed?

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

CODE Tags on the first post!!!! How did you happen to figure that out? Great!!!! :icon_mrgreen:

Please FORMAT your code properly. Change your IDE to replace TABs with 4 SPACEs. It is very difficult to read your code the way it's posted.

Don't you enter a single letter when asked? That would put the letter entered into letter[0] , not letter[i] .

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

Standard section 7.19.7.11 (The ungetc function) begs to differ.

Ahh, sorry. I forgot it's not related to getch() . My mistake.

But I still think it shouldn't be used.

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

Hi there,

Hi.

I have done a small exercise (ex 4.17 on C++ how to program - deitel and deitel) which basically is about writing a program that uses a while statement to determine and print the largest number of 10 numbers input by the user. The program should use 3 variables, counter, number and largest.
...
Now, this exercise was rather easy, so I was wondering whether it would be good practice to like use private members in the class: say, I could declare the variable in the class and make them private and then access them via a getter and change them with a setter. WOuld that have any advantage, or is it an unnecessary complication?
thanks

If you don't put any variables in the class, why bother with the class at all? I would do it as a good exercise.

Now let's consider your logic:
You call 1 function which does *all* the work. So why not just leave the code in main() and forget the function?

To make this program more sensible, break it up into it's components. A component should do only one job:
1) Initialize data - set all values to their initial states
2) Input data - accept data from the user
3) Process data - process the data input
4) Output results - display the answer

Each can be a method/function of the class. So your logic in main() becomes

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

thanks for the thorough response ravenous and red goose.

I have a quick question regarding your reply ravenous, when you said:

/* Check through things in argv here */

what exactly do you mean? I'm confused as to how I check things through.
Thanks!

argv[] is an array. Check argv[1], then argv[2], and so on until you run out, based on the value of argc.

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

But ungetc() is non-standard and therefore not recommended. It will not work in most compilers.

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

You'd be better off reading the entire line and looking through the array rather than trying to mess around with complex file reading techniques. If you can read the entire file, so much the better.

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

If the number must be exactly 5 digits, you'd be better off reading the number as a string and passing it into your function. By reading an int, you have the possibility of an error on the read if they type in a non-digit character. Reading a string removes that possibility.

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

Set the textbox ENABLED property to FALSE. The WebBrowser probably has the same value.