|
put it in the outer for loop or does it go with the declarations? i still get the error subscript out of range.
|
|
|
|
|
do you want me to e-mail a copy of my .cpp?
|
|
|
|
|
Chuck Vought wrote: put it in the outer for loop or does it go with the declarations?
Think about it. You are doing concatenation. At what point would name need to start over?
Chuck Vought wrote: i still get the error subscript out of range.
Making it a constant has nothing to do with the error.
Chuck Vought wrote: name[i] += letters[i%2][rand()%letterlength[i%2]];
name is not an array yet you are treating it as one. Remove the subscript.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
name[0]=toupper(name[0]);
firstname[j]=name;
name = "";
it says line 1575?
|
|
|
|
|
int main()
{
int numFirst, numLast,num,i,j,count;
int lowFirst=3, highFirst=12,lowLast=5, highLast=14;
cout << "This program will generate first and last names from\n";
cout <<"the number of names you choose." << endl;
cout << endl;
cout << "Please enter the number of names between 1 and 100 you want to \n"
<< "generate random first and last names for: ";
cin >> num;
while (num < 1 || num > 100)
{
cout << "\nInvalid number entered!! Please try again ..." << endl << endl;
cout << "Please enter the number of integers between 1 and 100 you want to\n"
<< "generate random first and last names for: ";
cin >> num;
}
cout << "\nPlease enter the number of letters(between 3 and 12) you want for your first name: ";
cin >> numFirst;
cout << endl;
while (numFirst < lowFirst || numFirst > highFirst)
{
cout << "\nInvalid number entered!! Your number must be between 3 and 12. \n"
<< "Please re-enter a number. \n";
cin >> numFirst;
}
cout << "\nPlease enter the number of letters(between 5 and 14) you want for your last name: ";
cin >> numLast;
cout << endl;
while (numLast < lowLast || numLast > highLast)
{
cout << "\nInvalid number entered!! Your number must be between 5 and 14. \n"
<< "Please re-enter a number.\n";
cin >> numLast;
}
string firstname[num],lastname,name;
static const int namelen = numFirst;
static const char* letters[2] = { "bcdfghjklmnpqrstvwxyz", "aeiouy" };
static const int letterlength[2] = { strlen(letters[0]), strlen(letters[1]) };
srand(time(NULL));
for (int j=0; j<num; j++)
{
for (int i=0; i<numFirst; i++)
{
name += letters[i%2][rand()%letterlength[i%2]];
}
name[0]=toupper(name[0]);
firstname[j]=name;
name = "";
}
for (int i=0; i<numLast; i++)
{
lastname[i] += letters[i%2][rand()%letterlength[i%2]];
lastname[0] = toupper(lastname[0]);
}
for(j=0;j<num;j++)
{
cout <<firstname[j].c_str() <<" ";
if(j<=5)
{
cout<<endl;
}
}
cout<<endl<<endl;
return 0;
}
|
|
|
|
|
Suggestions:
Chuck Vought wrote: string firstname[num],lastname,name;
vector<string> firstname; Chuck Vought wrote: firstname[j]=name;
firstname.push_back(name);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
still getting the error. i am lost as to what to try
|
|
|
|
|
Chuck Vought wrote: still getting the error.
Where?
Your code, coupled with my suggestions, compiles and runs fine.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
can you repost the code you ran and i will try it again.
|
|
|
|
|
Chuck Vought wrote: can you repost the code you ran and i will try it again.
See here then here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i have those in there. can you repost the entire code that you ran? i will put it in my compiler to see if I get any errors.
i am running VS2008 with a Vista OS, do you think there is a problem in one of these?
|
|
|
|
|
It is working without errors except that it seems to only create a first or last name with the number of character for firstname only. If i enter 3 for firstname and 10 for last name i still only get 3 letters?
vector <string> firstnames;
vector <string> lastnames;
string lastname;
string firstname;
static const char* letters[2] = { "bcdfghjklmnpqrstvwxyz", "aeiouy" };
static const int letterlength[2] = { strlen(letters[0]), strlen(letters[1]) };
srand(time(NULL));
for (int j=0; j<num; j++)
{
for (int i=0; i<numFirst; i++)
{
firstname += letters[i%2][rand()%letterlength[i%2]];
}
firstname[0]=toupper(firstname[0]);
firstnames.push_back(firstname);
firstname = "";
}
for (int x=0; x<num; x++)
{
for (int y=0; y<numLast; y++)
{
lastname += letters[i%2][rand()%letterlength[i%2]];
}
lastname[0]=toupper(lastname[0]);
lastnames.push_back(lastname);
lastname = "";
}
}
for(z=0;z<num;z++)
{
cout <<firstnames[z].c_str()<<" " << lastnames[z].c_str()<<endl;
}
|
|
|
|
|
How does this code even compile?
Chuck Vought wrote: lastname += letters[i%2][rand()%letterlength[i%2]];
Study this statement carefully.
Aside from that, your code produces:
Zyr Yayaouyeea
Yyv Yoiooioeyu
Qay Yiuooeyoeu
Zyh Uyiaauuiuu
Rok Ioiouiaooi
Les Oyauaiuiyu
Xam Aoieyuiaoy
Mij Oyeaaaoiya
Yuq Yyiuaoyooa
Hil Uayayyouyu which falls within your guidelines of a 3-letter first name and a 10-letter last name.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
From what you've shown num, numFirst and numLast have not been declared.
they are variables so how could i declare them? they are declared as int types.
|
|
|
|
|
Chuck Vought wrote: they are variables so how could i declare them? they are declared as int types.
http://www.codeproject.com/Messages/3160966/Re-Random-Name-Generator.aspx[^]
When you are asking for help and providing code snippets, the less guess work we have to do, the better. Since I am not you, I have no way of knowing if the compiler errors you reference go hand-in-hand with the code snippets you are providing.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i can send the .cpp file if you want to run it to see the errors do you want me to do that?
|
|
|
|
|
LOL, what a discussion
Why don't you post to let us know how you did at the exam or whatever it was?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I do want to post a message thanking all of you who helped me finish this program and get the code to do what I needed it to do. Especially David who was very,very helpful. Just to let you know I did pass and actually got a 100%. Once again thanks to all for your help. It was much appreciated.
|
|
|
|
|
Hi,
I'd like get some idea how to do it?
I displayed BMP image(full screen) in OnPaint fuction of SDI CView Window.(it's OK );
I'd like to flow a strings over the BMP image form right-bottom to left-bottom.
it is just like subtitle on TV...
How can I approach it to do it?
because I'm VC beginner ... Any comment will help..
Have a day.
|
|
|
|
|
in painting you draw at first the background and than draw the top painting stuff. So in your case you first draw the bmp and than draw the text. To draw nice the you got to create a own Font (CFont).
Here is some API-code:
BOOL DrawTextTransparent(HDC hdc, HFONT hFont, const RECT& rc, LPCTSTR pszText, UINT cnt)
{
HFONT hFontOld = (HFONT) ::SelectObject( hdc, hFont );
int iBkMode = ::SetBkMode( hdc, TRANSPARENT );
BOOL b = ::ExtTextOut( hdc, rc.left, rc.top, ETO_CLIPPED, &rc, pszText, cnt, 0 );//read the help
::SetBkMode( hdc, iBkMode );
::SelectObject( hdc, hFontOld );
return b;
}
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi,
Now i got 4 picture control and 4 button in 1 dialog. I can load the image into picture control, but when i load the second picture, the 1st image will disappear. How to make it fix to there?
Another problem is that, after load the image i need to minimize my windows and open it again, the image just can show.= =ll.
i'm still new in MFC..Anyone can help me?Thx
|
|
|
|
|
ok. i think the second problem i had solve it already.
just add the UpdateAllViews()...
The 1st problem still there..please advise.
|
|
|
|
|
You should be a bit more specific about your problem. Just saying something like "i have a button and if i press it what happens is not what i want, how can i fix it" won't tell us much about the actual problem. Show us some code snipplet, how do you load images into your 4 picture controls? Also, by "first image disappears" do you mean the newly loaded image "overwrites" the first one or the first one simly disappears from sight?
Since you say you have 4 pic controls and 4 buttons i guess that each pic control has a button which if you press, an image should be loaded into the corresponding picture control. I also guess that if you press the second button, not your second pic control gets the image but your first, and that is your problem. If so, i can generally think of 3 things that could cause this:
1. All 4 of your buttons have the same command ID (or at least, some buttons share the same command ID), thus, no matter which button you press, your program will get the same command ID and execute the same handler function which loads and image into the first picture control. Make your buttons have different command IDs so you can differentiate between them in code.
2. In the message map you specified the same function as a message handler for the buttons, so whichever button is pressed, the same function will be executed and will load the picture in the first picture control overwriting whatever was there previously.
3. Copy-paste bug, you have separate command IDs and separate handlers for your buttons but you copy-pasted the same code into each message handler and forgot to change the needed parts to make the handler load the image into the picture control belonging to the actual button, so whenever a button is pressed, the same code is executed and loads the picture into the first picture control.
Does any of this make sense?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Sorry for inconvenient.ok, i try to explain more detail.
In my dialog, i have 4 picture control to display the picture 1 -> picture 4
4 radio button to select picture 1->picture 4, and 1 button(Load Image button).
When the users click on the load image, the program will check the radio button now is on which picture, then load and display the picture into picture control.eg, if radio button now is on picture3,then the image must display in picture control number 3.
I had done this step,the image can display correctly. But when i click on another radio button,let say picture 2, the image previous show in picture control 3 will disappear. This is my problem now.but when i click back into radio button 3,it will show the previous image..
The image had store in memory..er..sorry for my poor English.hope you all can understand wat i saying...
|
|
|
|
|
Show some code, for example show us the code that runs when you hit the "Load" button and also the code that runs when a radio is selected (if any).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|