|
When i use the following code all works well for a while. If you enter the inner loop once it works fine but will not allow to enter it a second time. can someone explain this to me please or show me how to enter it again.
thanks.
<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
int main () {<br />
int number;<br />
int testval = 0;<br />
<br />
while (true) {<br />
cout << "Pick a number 4 quits" << endl;<br />
cin >> number;<br />
if (number == 4) {<br />
return 0;<br />
}<br />
else if (number == 1) {<br />
while (testval != 5) {<br />
cout << "pick a new number: ";<br />
cin >> testval;<br />
<br />
if (testval == 1) {<br />
cout << "inner loop 1" << endl;<br />
}<br />
else if (testval == 2) {<br />
cout << "inner loop 2" << endl;<br />
}<br />
else {<br />
cout << "inner loop 3" << endl;<br />
}<br />
}<br />
}<br />
else if (number == 2) {<br />
cout << "outer loop 1" << endl;<br />
}<br />
else {<br />
cout << "outer loop 2" << endl;<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Can you wrap your code in pre tags instead of code tags?
Unindented code is hard to read (for me anyway )
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
sure thing
#include <iostream>
using namespace std;
int main () {
int number;
int testval = 0;
while (true) {
cout << "Pick a number 4 quits" << endl;
cin >> number;
if (number == 4) {
return 0;
}
else if (number == 1) {
while (testval != 5) {
cout << "pick a new number: ";
cin >> testval;
if (testval == 1) {
cout << "inner loop 1" << endl;
}
else if (testval == 2) {
cout << "inner loop 2" << endl;
}
else {
cout << "inner loop 3" << endl;
}
}
}
else if (number == 2) {
cout << "outer loop 1" << endl;
}
else {
cout << "outer loop 2" << endl;
}
}
}
|
|
|
|
|
Once testval has been set to five in the inner loop then the inner loop will never be
entered again because testval is still 5.
Try this:
int main ()
{
int number;
int testval = 0;
while (true)
{
cout << "Pick a number 4 quits" << endl;
cin >> number;
if (number == 4)
{
return 0;
}
else if (number == 1)
{
while (testval != 5)
{
cout << "pick a new number: ";
cin >> testval;
if (testval == 1)
{
cout << "inner loop 1" << endl;
}
else if (testval == 2)
{
cout << "inner loop 2" << endl;
}
else
{
cout << "inner loop 3" << endl;
}
}
<code>testval = 0;</code>
}
else if (number == 2)
{
cout << "outer loop 1" << endl;
}
else
{
cout << "outer loop 2" << endl;
}
}
}
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
ahhh i'm silly sometimes.
thank you much for that i was going nuts truing to figure it out.
|
|
|
|
|
You just completed a homework assignment for him...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I use CPropertySheet create property sheet dialog.
I found that they has four button inside are OK, CANCEL, Apply and HELP.
How I disable or remove HELP button from property sheet dialog?
|
|
|
|
|
In the propertysheet constructor you put the following
m_psh.dwFlags &= ~(PSH_HASHELP);
and in each of the propertypage constructors put
m_psp.dwFlags &= ~PSP_HASHELP;
Then the help and apply buttons will be removed.
|
|
|
|
|
Tony Hill wrote: and in each of the propertypage constructors put
m_psp.dwFlags &= ~PSP_HASHELP;
This step will not be required here(in property page c'tor). As this flag deals with enabling/disabling help button, if it is there.
Prasad
MS MVP - VC++
|
|
|
|
|
hello,
here is sample code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){
}
//---------------------------------------------------------------------------
int* Instructions(int nr, int dydis, int &index){
int* instr=new int[dydis];
for(int i=0; i<dydis; i++)
instr[i]="i;
index=dydis;
return" instr;
}
="" ---------------------------------------------------------------------------
void="" __fastcall="" tform1::button1click(tobject="" *sender){
int="" *instrarr,="" size,="" index="0," i;
size="StrToInt(Edit1-">Text);
for(i=0; i<size; i++){
instrarr="Instructions(i," size,="" index);
}
for(i="0;" i<index;="" i++){
instrarr[i]="InstrArr[i]*InstrArr[i];
Memo1-">Lines->Add(IntToStr(InstrArr[i]));
}
delete[] InstrArr;
}
//---------------------------------------------------------------------------
i found out that :
for(i=0; i<size; i++){
instrarr="Instructions(i," size,="" index);
}
is="" working="" some="" how="" not="" correctly.="" could="" i="" make="" it="" to="" work="" properly?
=""
<div="" class="ForumSig">Dj_Lord
|
|
|
|
|
the code was printed somehow strangely..
here is the link for full code:
http://www.paste.lt/paste/508075a01ab2229c852d831278379bab
wrong lines: 28-30.
Dj_Lord
|
|
|
|
|
Dj_Lordas wrote: is working some how not correctly.
How so? What is "work properly"?
Every time through the loop you overwrite the previous InstrArr value.
All those arrays never get deleted.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
True and beyond that the code makes no since to me.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: and beyond that the code makes no since to me.
I'm right there with ya on that one
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i am very beginner in c++, could you show, how to correctly delete these arrays? could you write how the good code looks like?
Dj_Lord
|
|
|
|
|
I want Instructions() to make an array and i am not sure how should I do it..
i posted just the example showing the meaning the problem, so here is the full code:
http://www.paste.lt/paste/2daf3594d0c371fa73ec80d9ad4dfcb3
maybe now it will be easier to understand..
Dj_Lord
|
|
|
|
|
You're creating the arrays fine but not deleting them
int* instr=new int[dydis];
...
delete[] instr;
I'm not sure what you are trying to do in your code.
You use new and delete so the problem is not with array creation but is with the logic of the
code.
You have to eventually call delete on any of the pointers returned by new. Those pointers could
be stored in variables, an array, etc.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I knew that we can not create multi dimensional array with new. But in Navigating C++ and Object-Oriented Design book, it writes:
Type *pname = new Type[size]; <br />
Type (*pname)[size2][sizeN] = new Type[size1][size2][sizeN];
for example:
A (*pu)[1] = new A[1][1];
delete [] pu;
Is this example code really means that this is dynamic array? Or something different?
Assume that we create N-size array, Is it always enough to write delete[]?
Thanks.
|
|
|
|
|
Hi.
With Visual Studio 2005 and .NET it's too easy to consume and create a Web Service, but what about using MFC?. I got a MFC application, (a dialog based application), and I need to consume a Web Service, (created with Visual Studio 2005 in ASP.NET), how could I do that?. I know, SOAP is the answer, but I need a guide, (maybe there's an article already writen, or something like that).
Thank you and regards.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
|
Yes Mike!
That's what I need!!. Right on target!.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
hey everyone. can anyone help me with setting up a texture in visual studio.
heres my code just in case thats the reason why my texture isnt showing up.
thanks everyone!!!
#include <gl glut.h="">
#include <gl glu.h="">
#include <gl glaux.h="">
#include <stdio.h>
GLuint texture;
int width, height;
BYTE * data;
FILE * file;
void changeSize(int w, int h)
{
if(h==0)
h = 1;
float ratio = 1.0*w/h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45, ratio, 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0,
0.0, 0.0, -1.0,
0.0f, 1.0f, 0.0f);
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0); glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2d(-1.0, 1.0); glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2d( 1.0, 1.0); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2d( 1.0, -1.0); glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
GLuint LoadTextureRAW( const char * filename, int wrap )
{
// open texture data
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
// read texture data
fread( data, width * height * 3, 1, file );
fclose( file );
// allocate a texture name
glGenTextures( 1, &texture );
// select our current texture
glBindTexture( GL_TEXTURE_2D, texture );
// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// if wrap is true, the texture wraps over at the edges (repeat)
// ... false, the texture ends at the edges (clamp)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
wrap ? GL_REPEAT : GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
wrap ? GL_REPEAT : GL_CLAMP );
// build our texture mipmaps
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
GL_RGB, GL_UNSIGNED_BYTE, data );
return texture;
}
void FreeTexture(GLuint texture)
{
glDeleteTextures(1, &texture);
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(320, 320);
glutCreateWindow("Texure");
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
}
as a seal i will never insult the constitution, to kill and not to be killed, to die and not to be....died.
|
|
|
|
|
Dear all
we have a program(binary code) . We want to make it to have high process and thread priority.
is there any function or way that we can do this from an application which we write to make that program have high priority?
Also we have one Device driver which has one kernel mode thread in it.
Is there any way to change the priority of system thread of that driver?
we have only .sys version of that driver.
Regards
Monhi
|
|
|
|
|
Hi,
Does anybody know a tool for Visual Studio .Net, for programming in C++, that when changing a class / data member / function name - it can automatically rename all references to the class / member?
Thanks!
while (i == live) {
have(fun);
}
|
|
|
|
|