|
below is my code the whole program is for prompting user to enter 10 nos. b/w 20 to 100 it will while is there to check wheter the user entr the corect number or not, it will also check that the entered number is unique and was not previously entered by the user. at end of program simply it will display the non dublicate nos. whole program is correct but at end it is not displaying correct result . plz check the code n tell me wherz my mistake.
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
main()
{
int nTmp,j;
//declares variable bflag th be of type bool & intializes bflag to false
//bool is a data type whose value may be false or true
bool bFlag=false;
int a[10];
cout<<"entr 10 numbers b/w 20 and 100"<<endl;
="" for(int="" i="0;i<10;i++)" {="" cout<<"enter="" value"<<endl;
="" cin="">>nTmp;
while(!bFlag)
{
////Here we check first Condition
// no between 20 and 100
while((nTmp<20)||(nTmp>100))
{
cout<<"enter no b/w 20 and 100"<<endl;
="" cin="">>nTmp;
}
j=0;
while(j<=i)
{
if(a[j++]==nTmp)
{
bFlag=false;
}
bFlag=true;
}
if(bFlag==true)
{
//save variable
a[i]=nTmp;
}
}
//again make it false
bFlag=false;
}
cout<<" the non dublicate nos are "<
|
|
|
|
|
Madame Rose
rose aashii wrote:
cout<<" the non dublicate nos are "<<a[i]<<endl;< i="">
you forget to insert a Loop here i.e.
for(i=0;i<10;i++)
cout<<" the non dublicate nos are "<<a[i]<<endl;
cheers,
Alok Gupta
|
|
|
|
|
thnx but it is giving wrong output plz chk it n reply soon
rose
|
|
|
|
|
Here is full sourcecode i created for you because you are showing efforts, but i still insist that you read your Text Book.
#include<iostream.h>
void main()
{
int nTmp,j;
bool bFlag=false;
int a[10];
for(int i=0;i<10;i++)
{
cin>>nTmp;
while(!bFlag)
{
while((nTmp<20)||(nTmp>100))
{
cout<<"enter no b/w 20 and 100"<<endl;
cin>>nTmp;
}
j=0;
while(j<=i)
{
if(a[j++]==nTmp)
{
bFlag=false;
cout<<"You already entered this Number!enter unique no "<<endl;
cin>>nTmp;
break;
}
bFlag=true;
}
if(bFlag==true)
{
a[i]=nTmp;
}
}
bFlag=false;
}
for(i=0;i<10;i++)
cout<<a[i]<<endl;
}
cheers,
Alok Gupta
|
|
|
|
|
the same code i tried.. my prob is that i need to print only dat numbers that r not repeated.like if i entered 50, 60, 80, 90, 99, 56, 50,98, 45, 99 so here 50 and 99 are reapeating so in the output ony 8 nos that r 50, 60, 80, 90, 99, 56, 98, 45 such that the nos that r repeating should not be displayed as u observe it in output.this is not diaplyind the ouput which i want.
for(i=0;i<10;i++)
cout<<" the non dublicate nos are "<
|
|
|
|
|
I have programed it that way that it will take only 10 unique numbers!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Is there anyway that I can cast a graphics path to a bitmap?
Im trying to make a freehand sketch program using John Buettner's example, the problem is that when changing the pen color and width it effects everything drawn into that path previously. I figured the best way to do it would be casting the graphicspath into bitmap format on mouseup and then resetting the graphicspath though after playing around with it quite a bit im still not sure how to go about it.
Any help appreciated thanks.
|
|
|
|
|
Why not just save the pen size and colour information along side every path?
cheers,
-B
|
|
|
|
|
OnKeyDown(UINT nChar, ...)
{
char lschar = char(nChar);
if (lschar=='A') AfxMessageBox("Key A is pressed");
}
In the same way, how to test when key: UPARROW, LEFTARROW, RIGHTARROW, DOWNARROW, NumPad-, NumPad+ is pressed.
thanks for help me!
don't stop me now!!!
|
|
|
|
|
I use an easy method it seems to work.
onkeydown(UINT nChar....)
{
CString string;
string.Format("%d",nChar);
AfxMessageBox(string);
}
This func. tells you the code whic you press.
|
|
|
|
|
switch (nChar)
{
case VK_UP:
// up arrow
break;
case VK_LEFT:
// left arrow
break;
case VK_RIGHT:
// right arrow
break;
case VK_DOWN:
// down arrow
.
.
.
}
suhredayan There is no spoon.
|
|
|
|
|
as usual you are always FAST
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
as usual you are always FAST
hope you don mind
suhredayan There is no spoon.
|
|
|
|
|
suhredayan® wrote:
hope you don mind
if you don't mind i will reply that in HINDI
"Mind karne ke liye MIND ki jaarorat hoti hian"
In English
"it require MIND to MIND"
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
"it require MIND to MIND"
I thought 'mind' comes as default and free with every package. Is it removed nowadays coz of complaints from 3rd party mind builders ?
suhredayan There is no spoon.
|
|
|
|
|
suhredayan® wrote:
Is it removed nowadays coz of complaints from 3rd party mind builders ?
Yes, testing Deptt Complaint about this! and programmer removed that :->
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
unidentify wrote:
onkeydown(UINT nChar, ...)
{
char lschar = char(nChar);
if (lschar=='A') AfxMessageBox("Key A is pressed");
}
change this to
onkeydown(UINT nChar, ...)
{
char lschar = char(nChar);
if (lschar==VK_UP) AfxMessageBox("Key UP is pressed");
}
for rest you can make yourself here is Virtual keycode for them VK_RIGHT VK_DOWN VK_LEFT VK_ADD VK_SUBTRACT
cheers,
Alok Gupta
|
|
|
|
|
I'm writing a file parser. It's really pretty simple. Here's a sample file:
B C 25
A D 36
D E 63
B A 48
C D 30
D B 52
E C 30
C P 30
P Q 52
Q X 51
X Z 70
Z X 20
X Q 20
*
My question is this: Notice that blank line in the middle? How, in C++ using ifstream, can I detect when the parser reaches a blank line such as that one, but still be able to continue parsing?
Thanks for any help!
|
|
|
|
|
There is Function for detecting EOF() using that you can read your file upto last end of file!.
Now for detecting and ignoring Blankline, read file line by line (yeah ifstream has function to do so)and then you can check for empty line easily by using strcmp().
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Hi,
This line is not a blank line.
The legnth of that line is 1 and it's containing '\n'(0x0d).
Regards,
Eli
|
|
|
|
|
Thanks. That helped some, but I'm still not sure how to do it. I'm fairly experienced with C++, I've just literally haven't ever used standard file input and output interface, so I'm really pretty stumped. Here's the code for the parser (note this isn't the only code I've written though, I have a lot more that's not the parser):
CompanySetVector CompanySets = CompanySetVector();
ifstream InputFile ("company.in");
ofstream OutputFile("company.out");
string A, B;
float cAB;
int CurrSet = 0;
CompanySets.push_back(new CompanySet);
InputFile >> A;
while (A != "*") {
if (InputFile.peek() == '\n') {
CompanySets.push_back(new CompanySet);
CurrSet++;
}
InputFile >> B;
CompanyDef* pA = CompanySets[CurrSet]->second[A];
CompanyDef* pB = CompanySets[CurrSet]->second[B];
if (pA == NULL) {
CompanySets[CurrSet]->second[A] = new CompanyDef(A);
pA = CompanySets[CurrSet]->second[A];
}
if (pB == NULL) {
CompanySets[CurrSet]->second[B] = new CompanyDef(B);
pB = CompanySets[CurrSet]->second[B];
}
InputFile >> cAB;
ControllingInterest* ci = new ControllingInterest;
ci->first = pB;
ci->second = cAB;
pA->ControllingInterests[B] = ci;
InputFile >> A;
}
Most of that code is pretty project specific an irrelevant to you.
Notice the line:
if (InputFile.peek() == '\n') ...
This is where I need to see if the line is blank. I thought using peek would work, but it doesnt
Do you guys have any other suggestions? Again, thanks for taking time to read this!
|
|
|
|
|
Hi,
Why don't you use FILE instead of ifstream and ofstream?
It's work like this:
FILE *InputFile,*OutputFile;
char InputFileName[] = "company.in";
char OutputFileName[] = "company.out";
char *LineFromFile = new char[100];
CString string;
InputFile = fopen(InputFileNAme,"r");
OutputFile = fopen(OutputFileName,"w");
if(InputFileName == NULL)
{
AfxMessageBox("Unable to open input file");
return;
}
if(OutputFileName == NULL)
{
AfxMessageBox("Unable to open output file");
return;
}
while(fgets(LineFromFile,100,InputFile)!= NULL)
{
string = LineFromFile;
if(string.GetLength() == 1)
{
if(string == '\n')
{
continue;
}
}
else
{
}
}
Good luck,
Eli
|
|
|
|
|
i think that using ifstream and the "<<" operators (forgot what it's called...) will get u what u want.
do something like this:
while (!file.IsEOF()) // read all lines, even if it's blank.
{
__file >> B;
}
if (!B.empty()) // forgot if this works or not. think it should.
__// do the required operation here.
anyway think my code is pretty unclear. here's the explanation.
just keep readin the file, and before performing the push_back operation for the vectors, check that the string is not empty. this will prevent empty string from being written into the vectors. and as the IsEOF() function stops the while loop only on eof, the blank lines will be read.
hope this is correct, as i'm coding off-line here.
|
|
|
|
|
I've tried to look for help here on Codeproject and elsewhere but the only pages I found are ones to automate opening an image and displaying it but I need to do something a little different. I have a valid bitmap image file, however, I also have bitmap data stored elsewhere. Is there a way I can display the bitmap using the data stored elsewhere but use the former valid bitmap images' header and palette data to display with. I tried inspecting some data types to simply display the bitmap but I can't find an obvious way to intercept the loading and simply point a pointer to the new area in memory where the data exists.
I know I could simply write the header to a new file followed by the new data and show that but I'd like to leave less of a footprint behind and streamline the process. Thanks in advance for any help you can give, Nate.
Edit: I guess I never really can find out a good explanation as to what each command does in order to display an image. Too many sites are interested in just telling you how to do it, instead of explaining how to do it; I guess programmers are in that much of a hurry.
|
|
|
|
|
I have an application which uses shared memory, but when I tried to modify this application (which has a different shared memory structure), I keep getting the the old shared memory names.
At run-time if I set a breakpoint an examine the shared memory pointer is has the new data structure. However when I examine the pointer during edit is contains the old memory names.
BUT I cant set data to either the old or new names.
Can I clear out the old names, or am I going mad?!?
I have searched for the old names and they are not present in the project.
grahamfff
|
|
|
|