|
The first problem is that you are incrementing the variable i even if the number entered is out of range. The other problem is that you have a second, unnecessary call to cin .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
the code that u have written.....
only checkz for the validity of th enumber the first time(coz u have used 'if' construct! replace it by 'while'!!!!
it should be.....
for(i=0;i<10;i++)
{
cin>>a[i];
while((a[i]<20)||(a[i]>100))
{
cout<<"entr no b/w 20 and 100"<<endl;
cin>>a[i];
}
}
to check if the number was entered or not before.....u have to check the array,then accepet or reject accordingly.....
i hope thiz aint ur homework!!!!!.....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
|
Michael Dunn wrote:
How can a number be less than 20 and greater than 100 at the same time?
Only those numbers that have crossed over to the dark side.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
oopz.....i just seemed to have just noticed the "&&".....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Your loop structure is wrong. You should use a while loop to count the number of correct numbers (unique numbers between 20 and 100).
input your candidate value
while the number of unique numbers between 20 and 100 is less than 10 do the following
if candidate value is valid then assign it to your array and incremment your valid numbers count
get the next candidate value.
to check the validity of your candidate value you have to do the range check as you already figured out, and then you have to search through your array (up to the current number of valid values) for any values that are equal. If you find a match then your value is not valid.
This should give you some help. But as stated, your assignments will not be done for you. Try to put this description into code. And let me know if you have further trouble. Do it quick I probably will not be online much longer. Its the weekend and I have house work to do
|
|
|
|
|
Bob Flynn wrote:
Its the weekend and I have house work to do
Are your weeds screaming at you too?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Yea, but not as loudly as my wife is to cut them.
|
|
|
|
|
In Continution with Mr Rateep Code :-
for checking entry of Unique Number
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;
}
cheers,
Alok Gupta
|
|
|
|
|
gack... that's a hell of a long code just to check for unique numbers.. if all u're interested in is getting is getting unique numbers, why not use STL to do your work for u?
look at this link: http://www.cppreference.com/cppset/[^]
using a set stl, it automatically keeps only the unique numbers during an insertation. and by using the pair<iterator,bool> insert( const TYPE& val ); esp, the bool, u can check if the insertation took place.
for the lazy coder (that's me), my insert statement is:
if (!(mySet.insert(myVal)).second) // so i don't have to use declare a pair
cout<<"insertation has failed as it is duplicate."<
|
|
|
|
|
ng kok chuan wrote:
.. if all u're interested in is getting is getting unique numbers, why not use STL to do your work for u?
You are correct Buddy!,but owner of this problem seems to be beginner in C++ as you see She getting difficulty in running Simple loop so we can't expect her to program using STL.
Anyways i willtry to leran from this link! i too very weak in STL
cheers,
Alok Gupta
|
|
|
|
|
I'm writting a dialog-based application. The dialog has the popup style (no title bar needed), and the problem is so that i can see its text in the taskbar, but no icon
The icons' wizard code (WTL) has been let intact but with no visible effect.
Do you know how could i fix the unusual behaviour?
"though nothing
will keep us together
we can beat them
for ever and ever"
rechi
|
|
|
|
|
Bogdan Rechi wrote:
I'm writting a dialog-based application. The dialog has the popup style (no title bar needed), and the problem is so that i can see its text in the taskbar, but no icon
The icons' wizard code (WTL) has been let intact but with no visible effect.
i amn't able to reproduce your problem in WTL!, cod eyou send me demo code so that i can look into it!
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
cod eyou send me demo code so that i can look into it!
I already modified the code so that it minimizes in the systray. I can't send it to you anymore...
But, you could easily reproduce the behaviour. Just create a new dialog-based WTL project, open the dialog from the ResourceView tag, change the style to popup and disable the title bar option. Then run it, and you'll see what is all about.
Anyway, thank you for your effort
"though nothing
will keep us together
we can beat them
for ever and ever"
rechi
|
|
|
|
|
Bogdan Rechi wrote:
But, you could easily reproduce the behaviour. Just create a new dialog-based WTL project, open the dialog from the ResourceView tag, change the style to popup and disable the title bar option. Then run it, and you'll see what is all about.
there result here is just reverse what you mentioned here i am able to see ICON but not text. thats why i ask you for your code!
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
i am able to see ICON but not text
Ok, may i use the gmail address from your web page?
"though nothing
will keep us together
we can beat them
for ever and ever"
rechi
|
|
|
|
|
Yeah you can!
cheers,
Alok Gupta
|
|
|
|
|
Hi all!
Setting up a multi-developer Visual C++ project, which non-code files (i.e. not h- or cpp-files) would You include for source control?
Obviously, all h- and cpp-files dhould be included, but then what? There has been some debate going on at the office on whether for instance the dsp and dsw files should be configured.
A concrete example: we have suffered problems with what files/classes show up in a clients view after a sync to head following the check-in of new files/classes by another developer.
By the way, we are using Perforce. Your input will be much appreciated!
------------------------------------------------------------
"Pooollyyy!! ...Polly Parrot! Wakey-wakey!"
|
|
|
|
|
Less than a minute after posting my question I googled out the following page:
http://www.perforce.com/perforce/doc.031/manuals/p4plugins/02_visualcpp.html
Scroll down to the second last heading; "which files do I put in the depot?".
Any additional thoughts and input on the subject from You guys out there are still much appreciated!
------------------------------------------------------------
"Pooollyyy!! ...Polly Parrot! Wakey-wakey!"
|
|
|
|
|
DSP's yes, DSW's no.
If you are relying on your DSW to build the project correctly (via project dependencies), that's not a good thing. DSW's are intended for per-developer settings, DSP's for project settings.
Lets be honest, isn't it amazing how many truly stupid people you meet during the course of the day. Carry around a pad and pencil, you'll have twenty or thirty names by the end of the day - George Carlin
Awasu 2.1.1 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
its output is 47, why?
#include "stdafx.h"
#include <iostream.h>
class base
{
int i;
public:
base(base&){}
base(int I=0):i(I){}
virtual int sum(){return i;}
};
class derived:public base
{
int j;
public:
derived(derived&){}
derived(int I=0, int J=0):base(I),j(J){}
int sum(){return base::sum()+j;}
};
void call(base b)
{
cout<
|
|
|
|
|
ur base class callz both the constructorz(when u mention one parameter)(i mean it callz the base(base&)thatz why.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
Hello,
You wonder why the output is the same as the value j from your d
Well the problem is this: You have a very huge error in your classes that messes up the stack pretty badly.
Let me elaborate.
You have 2 errors: first your copy constructors, second your function call.
The first error is that your copy constructors do not return a class object. This alone doesn't cause the bug alone.
The second error is that your functions call accepts a non reference object argument. This isn't a direct error (sometimes even no error), but in your program it is. This is because it takes more time to pass an object and most of the time, you don't want you object to be copied like that.
These two errors lead to the following: when call() is invoked, the copy constructor of b is invoked. This constructor does not create a object and therefore the stack gets messed up. In the function call the variable b points to the wrong object on the stack (which is d ).
You can easy test this behaviour by changing the value of d.j , by removing the empty copy constructor or by passing b as a reference to call() .
Hope this helps you to understand the problem.
I also got the blogging virus..[^]
|
|
|
|
|
It's because call() takes the paramater by value and not by reference. Because you've declared it to take the parameter by value, the passed object gets *sliced*. So even if you pass an instance of derived, it gets sliced and only the base part of the objects is passed to call. The sum function call then executes on the sliced base instance and so you get 47 and not 57
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|