Other than minor formatting and C++ in the title (what forum is this?), your first post is quite good.
What constitutes the beginning of a sentence? How can your program recognize it?
Other than minor formatting and C++ in the title (what forum is this?), your first post is quite good.
What constitutes the beginning of a sentence? How can your program recognize it?
If you enter ^v or backspace, you can display the integer value of the keys to find out what to compare the key value to.
-if i cant call main, how do i make it start from the top of main if they type incorrectly?(tried *main(); and &main(); also, if thats considered calling main i will not do it anymore)
Let's restate the problem... How do you loop back to the beginning of the program?
Try writing a test program to see how you can apply this hint. Get to the point you understand how that works (complete with the YES/NO question).
Then write another test program to try one more single task you need to accomplish. Now merge these two tests.
Continue in this manner.
Question 1.will cin.getline()only stream in 1 line, instead of cin >> file, and if so,how do you go about this with alphabetizing.. What I am thinking is: cin.getline() will stream in 1 line, maybe at a time, and then you can call the swapNames function after the first cin.getline(), and if that second line's first int is smaller than the first lines, switch the second line to the first.
How about read in each line and sort the lines using the bubble sort. You already suggested it.
Question 2. How do i go about converting the char array that has the text file in it, into integers. I've never had to do this, and I've heard it makes the process easier using int.
Good question. What integer would you convert "Jones, Frederick M" into?
And stop thinking in terms of character arrays. You already posted that you should "use the C++ string class." That solves all of your questions in one C++ type.
i know the number that doesnt work is when range gets changed to zero
so i want program to know that when range equals zero it doesnt have to guess to more, it should know that the number
i know you can do this with the else statement and that is where my trouble is how input that statement in my code.
Then I will rephrase:
With pencil and paper, go through your code line by line using the number that doesn't work and see what happens when you get to that range. What needs to change in the code right there.
Are you executing the code by hand to see what happens with the number that doesn't work? Follow each statement with pencil and paper and write down each variable and watch it change. You should find out where it goes wrong.
Thanks for the fast response! That's a one way to do it but I was looking for something of the nature of traditional bubble sort. Comparing and swapping words next to each other and go through all the passes while there's a same character being compared, move on to the 2nd position of char and do sorting there. What I understand from the code you provided, it's comparing entire word to word, rather than individual characters of each positions-compare 1st char of words, if the char is the same, compare 2nd char and so on.
So in the standard BSort form, you need a K loop to look at individual characters. No biggie.
for i=0...
for j=i...
for k=.... ;; Loop through each character.
But, my way shows you a new and useful concept rather than simply adding to the known sort algorithm.
My apologies this should be better
Somewhat. Please actually READ the link. There are still problems with your formatting. Yours, too, gerard4143...
Also is fgets just a security issue because the program still doesnt respond
What does this mean?
The problem you have is you didn't think through the problem yet. I'll bet you just started coding...
for(int i = 0; i < strlen(string1);i++){
//selects the three characters to be compared
for(int j = i; j < i + 3; j++){
temp[j] = string1[j];
}
If string1 is ABCDABCDE and i=8 what's going to happen in the j loop?
//pointer to where the occurance is
ptr1 = strstr(string1,temp);
Which occurrence is this statement going to find?
Create a second array which contains indecies into your array of strings. For example:
ArrayList= "0hello", "1axe", "2help", "3nice", "4camper", "5ocean"
ArrayPntr= 0,1,2,3,4,5
Now as you test ArrayList use ArrayPntr to get at the values:
for i=0 to 5
if ArrayList[ArrayPntr[i]] .GT. ArrayList[ArrayPntr[i+1]]
swap only ArrayPntr[i] and ArrayPntr[i+1]
I repeat:
You are using the size of full to test characters in temp. Are you sure temp has >= characters than full? Display the values and see.
i have tried using
while(getchar()!='\n');
to clear the buffer , is there any other way / method? is there a simpler way to do this ?
Thanks
Can't get much simpler than that...
Or how about
Private Sub cmdremove_Click()
For i = list1.ListCount - 1 to 0 step -1
If list1.Selected(i) = True Then
list1.RemoveItem i
End If
Next i
End Sub
Start at the end and move to the beginning.
You are using the size of full to test characters in temp. Are you sure temp has >= characters than full? Display the values and see.
And does your compiler support C99?
The values it returns are:
1367821597
-2
2001180890
2001248506
4788024
4787832
2293528
2001248029
0
0
2147315712
180
172
3023400
43
2
2293544
2001247796
2293608
4198592
That shows you exactly what I mean. If you don't set the initial value of a variable -- ANY variable -- to a value, you have no idea what the value is. Saying int x;
does not make x a 0. It could be anything.
So when you use a value, unless you initialize it in some manner ( x = 3;
for example) your data is unknown. Print it, you get junk. Use it ( b = x*3;
) and you get junk.
Note to others: Yes I know about global variables -- ignoring them....
First thing you need to decide is what happens if 2 or more characters are entered? If this is not a concern, just use cin.get()
. Keep in mind all the extra characters will be waiting for the next input. That can mess the user input up royally.
If it is a concern and you only want the first character, read the entire line into a temporary string and move the character into the input string.
Third option is jonsca's suggestion.
I assume you can use arrays since you are already using pointers.
Are you also aware that each character value is just a number? 'A'=65, 'B'=66, 'a'=97...
You can set up an array of 256 set to zero and use each character as an index to increment the values. This will count each individual character -- letters, digits, spaces, everything.
Then once you've accumulated all the counts, simply add the ones you need: totVowels = count['a'] + count['e'] + ...
You need to read the input as a character string. Then look at the string and make sure every character is a digit. If so, convert to integer, if not display an error.
Since you process choice even when it's 11, my guess is nameArray[11-1] is beyond the array bounds.
I think I've followed the formatting rules fully and here's the code I have.
Except for the TABs to SPACEs part... Otherwise, it looks much better.
My confusion is coming from the x variable and the array size.
I don't understand what x is, unless it's a count for the columns, and every time x increments, we're moving to the next column.
Call me dense, but if you don't understand what x is, why is it in your code? Since you wrote it, you need to know what each variable is.
With the array size, does
char[s][6]
specify 6 wide, or 7 wide? Does this mean to make the array 6 characters wide I should change the 6 to a 5?
Because I know that it starts at 0, but I assumed that for size it's different and
Why would it be 7? It's a 6. Reread what I posted last time, and check it with your book. Why aren't you looking this stuff up in your text?
I also have continually returned outputs similar to this: 0x22fea0
And was wondering what causes it.
You never initialized any values, so there's garbage in the variable.
Run this:
#include <iostream>
using namespace std;
int main()
{
int v[20];
int i;
for (i=0; i<20; i++)
cout << v[i] << endl;
return 0;
}
What values do the uninitialized array contain?
Yes, format your code! If it's not formatted next time, you're on your own. I already gave you a link to look at.
If your definition is char a[s][6];
and you changed the assignment to a[x][6] = r[i + j];
, I would expect it to blow up. You are writing beyond the limits of the array. The second index can only go from 0 to 5. 6 is beyond the range.
Sorry, this is what I tried:
for (i = 0; i < 5; i){ for (j = 0; j < 30;j){ //couldn't understand the by 6 part of your suggestion a[x] = r[i + j]; //this line shows "error 32 incompatible types in assignment of `" x += 1; j++; } i++; }
If it's completely not what you meant, I'm sorry, a little new to this
No, it's not quite.
First, please learn to format your code. If the code is difficult to follow, it's difficult to help. I like the way you format each line, but the indentation is extremely important throughout the program. Be consistent.
Second, in the statement for (i = 0; i < 5; i)
, what is the last useless i for? That should be i++. Yes, I see it at the bottom of the loop, but that's not where it goes. All you have is a while
loop using for
Third, my code said for j = 0 to 30 [B]by 6[/B]
. You do that by adding 6 to j: for (j = 0; j < 30; j[B]+=6[/B])
Last, x += 1;
is better written as x++;
-- but you probably know that.
The best debugging tool you have is cout
. Display the variables at various spots in your program to see what's happening at key statements.
I'm afraid I have no idea what you are suggesting, I tried messing with your pseudo-code but I get it to work.
Since I can't see what you tried, I can't point out what you did wrong.
@WaltP: i is the "loop variable" its the one that increases in the for loop.
Good.
in1 es the initial value of i, and it changes depending on user imput. If the user want to print the rest of the map values, it increases in1 by 10, so the next time it runs the for loop instead of being 1 its 11.
Then why did you implement it as a function prototype? int in1(1);
is not defining a variable in1, it's specifying a function (notice the parentheses).
What you want is int in1=1;
Same applies for in2, except its the last value of i, so if the user wants to see more map values, its increased by 10. Thats what lines 22 and 23 do.
Yes, the same applies.
And, embooglement, at these forums we don't "fix up a bit" the code of others. We give help and let them fix the code. We have enough trouble with their professors getting POd at the students because someone hands them their assignment on a silver platter.
So use loops. The first assignment:
{r[0],r[6],r[12],r[18],r[24],r[30],
r[1],r[7],r[13],r[19],r[25],r[31],
r[2],r[8],r[14],r[20],r[26],r[32],
r[3],r[9],r[15],r[21],r[27],r[33],
r[4],r[10],r[16],r[22],r[28],r[34],
r[5],r[11],r[17],r[23],r[29],r[35]};
can be written as:
x = 0
for i = 0 to 5
for j = 0 to 30 by 6
array[x] = r[i + j)
x = x+ 1
next j
next i
Look for the pattern in the other assignments.
BTW, I lived a couple of years in Pullman, Wa.
That's your problem. There are different programming rules for the rest of the world :icon_twisted: (just kidding)
Now, explain to me what the line int i, in1(1), in2(11),a;
does, and how the variables relate to the line for (i = in1; i <in2; ++i)
Heres the code as is, without gutting. I didn't put the load map function, but it loads succesfully.
Maybe so, but I believe, as embooglement also believes, the code posted doesn't even compile. So back up and tell us what the real problem is.
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.
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.
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.
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.
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.
You can't compare a single character ( szSentance[i]
) with a string " \" "
), especially a 3 character string. Single quotes represent a character: '"'
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.
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.
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).
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.
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.
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.
Did you try outputting the two values (oldTime/currentTime) to see if they hold data that looks correct?
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.
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
?
Look up the mid
function and put it in a loop.
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.
Why do you want to programatically move the mouse? Just call the mouse click events directly with the proper parameters.
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.
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?
No, do not use getch()
. That is a non-standard C function (not even C++) in only a couple compilers. Use gerard's solution.