|
reyyy wrote:
if (c <code>=</code> 1) {
cout << "Hey!" << endl;
}
if (c <code>=</code> 2) {
cout << "Hmm!" << endl;
}
if (c <code>=</code> 3) {
cout << "What!" << endl;
}
Three words, dude... Warning Level 4 !
Those are assignments, not equality tests.
BTW - the app is closing quickly because it is running to completion. Make it wait for input or something in order to keep it running.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
How do i assign cin to this code for user input?
|
|
|
|
|
reyyy wrote: if (c = 1) {
Had you put the constants on the left of the operator, you would have quickly spotted the error.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
reyyy wrote: How do i assign cin to this code for user input?
in short, you should go back to your homeworks/lessons.
in long :
#include <iostream>
#include <conio.h>
void main() {
int c = 0;
std::cout << "Enter number from 1-3:" << endl;
std::cin >> c;
if (c == 1) {
std::cout << "Hey!" << endl;
}
else if (c == 2) {
std::cout << "Hmm!" << endl;
}
else if (c == 3) {
std::cout << "What!" << endl;
}
else {
std::count << "unknown value typed !" << endl;
}
getch();
}
ps: don't worry about my std:: , i just don't like the using namespace std
ps2: avoid global variables (see that i declare c inside the main function.
ps3: if you declare a function of type int , it should return a value (otherwise, declare it void - what i did here)
ps4: don't write successive if like you do, because the compiler will have to do every tests even if one is already succeeding. prefer using the else if statement for this.
-- modified at 12:27 Tuesday 27th February, 2007
can someone explain me what's wrong with this post to get rated like it is ?
|
|
|
|
|
std:: is the same as using namespace std; , right? and why did you use void main() instead of int main() ?
|
|
|
|
|
reyyy wrote: std:: is the same as using namespace std; , right
not quite. when you write an identifier, the compiler searches is it the namespaces imported, and in the global namespace. but using too many namespaces at the same time can issue into name ambiguities. so as writing the whole identifier name is not so hard to do, i prefer letting the things clear for the compiler AND for the readers of my code...
reyyy wrote: and why did you use void main() instead of int main() ?
this answer is in my previous reply. as you have no return statement in your main, you ave then no need to return a value, thus the void .
|
|
|
|
|
how can i assign cin to this part
if (c == 1) {
cout << "Hey!" << endl;
}
if (c == 2) {
cout << "Hmm!" << endl;
}
if (c == 3) {
cout << "What!" << endl;
} else {
cout << "Wrong!";
}
?
-- modified at 10:26 Tuesday 27th February, 2007
|
|
|
|
|
reyyy wrote: how can i assign cin to this part
i don't really get you.
don't you see the following line in the sample i gave you previously ?
std::cin >> c;
this line waits for a user input, and puts the value typed into c.
then, the process is that once the value is set, you can test it (thus the if s)
|
|
|
|
|
Well, sorry, but i have used only global namespaces, and i don't know much about this form std:: ,
that's why i was aking how can i assign cin without std::
And btw, when i put user input, program closes, without giving back statements from cases.
|
|
|
|
|
that's exactly why i don't like the infamous using namespace . you do things, but don't know at all what you're doing actually.
cin is never defined in the global namespace (otherwise, you would have been able to write ::cin without any compiler errors - that's not the case).
don't worry about the std:: . simply see it as saying "cin is in the standard namespace".
when you say using namespace std; , then every identifier (which namespace is not precised explicitely like i do) will be searched in the namespace imported.
that's good practice to never use (or at least reduce significantly the use of) using namespace . if you really feel the need of it, then prefer if inside a method rather than at the beginning of a whole cpp or .h file. that's how problems come !
|
|
|
|
|
IMHO I suggest you ask her to change it to "int" main and return something rather than opting for "void" and return nothing. It's said as the best practice particularly for the "main()". Can I be right toxcct?
Press: 1500 to 2,200 messages in just 6 days? How's that possible sir?
Dr.Brad :Well,I just replied to everything Graus did and then argued with Negus for a bit.
|
|
|
|
|
VuNic wrote: IMHO I suggest you ask her to change it to "int" main and return something rather than opting for "void" and return nothing. It's said as the best practice particularly for the "main()". Can I be right toxcct?
If you want your main() function to return an exit code, then you could return an int , or char , or whatever. It is perfectly safe to have a void main, too.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
Hi,
Can explain me about the mail merge concept in Vb.Net, Crystal Report, Word Doc, Excel Document
Thanks
|
|
|
|
|
Hello,
I know what mail merge means for Word. I don't know what it means for others.
In Mail merge one letter or document is attached to name or addresses of people stored in a data file.
So suppose you have typed a letter and you want to post it to 100 persons and each of these letters should have the name printed on the document then mail merge enables you to do that.You have to type one letter ,store name address etc that is the individual details in a data file and attach both of them in the mail merge procedure.When printed you will get 100 letters with particular info in place of the letter.
Prithaa
|
|
|
|
|
Here Visual C++ / MFC forum
|
|
|
|
|
I have a multi lined richtext control (the native Win32 version).
As I add a new line of text I want to vertically scroll to the last line of added text. How do I do this? I recall trying in the past and running into problems, and I'd like to fix this once and for all. Are there certain specific style bits that need to be set? Something else? EM_LINESCROLL didn't seem to act like I thought it would.
|
|
|
|
|
I think the style ECO_AUTOVSCROLL set it with CRichEditCtrl::SetOptions may be the answer, combined by CRichEditCtrl::SetSel(-1,-1).
Society is composed of two great classes, those that have more dinners than appetite, and those who have more appetite than dinners
Fold with us! ¤ flickr
|
|
|
|
|
Will that do it all the time (I don't want that)? I need it to be explicitly controlled programatically.
|
|
|
|
|
I made some tests and what I said was wrong, sorry. However, I may have found a way to do so based on the behavior of CRichCtrlEdit.
If you scroll to the end of a richedit, you will see that when you add text the richedit will scroll automatically. If the last line is 'below' the visible area, the richedit will not scroll.
A way to automate this is by using CRichEdit::LineScroll. The problem is to get the number of lines to scroll.
I tried this way:
<br />
long iStart, iEnd;<br />
m_RichEditCtrl.GetSel(iStart, iEnd);<br />
<br />
int iIndex = m_RichEditCtrl.GetLineCount() - m_RichEditCtrl.GetFirstVisibleLine();<br />
CDC *pDC = m_RichEditCtrl.GetDC();<br />
CFont *pFont = m_RichEditCtrl.GetFont();<br />
CFont *pOldFont = pDC->SelectObject(pFont);<br />
CRect clientRect;<br />
<br />
m_RichEditCtrl.GetClientRect(&clientRect);<br />
<br />
TEXTMETRIC tm;<br />
pDC->GetTextMetrics(&tm);<br />
pDC->SelectObject(pOldFont);<br />
<br />
int iCount = (int)((double) clientRect.bottom / tm.tmHeight) + 1;<br />
<br />
m_RichEditCtrl.LineScroll(iCount);<br />
And to put the last line 'below ' the richedit scope:
<br />
m_RichEditCtrl.LineScroll(-1);<br />
It's not perfect, I didn't test all the cases, but it 'globally' works
Society is composed of two great classes, those that have more dinners than appetite, and those who have more appetite than dinners
Fold with us! ¤ flickr
|
|
|
|
|
Hi all.
I write install project, I debug it and now I wont release my project, but I have proble.
Problem is thet debug wersion works and release not ??
my project conteins some windows service and API to controll service [Install, Start, Stop, Remove,write ini file].
I write anoder instalator, but . . .
In this case I need release version of project.
If service is debug version windows colls debager avry time I try to start service.
|
|
|
|
|
This[^] article is for you...
|
|
|
|
|
I have written a message handler on WM_RELEASEDCAPTURE event of Tab control.
But my problem is that Tab control generating this event only when its TCS_BUTTONS style is set.
Can any one explain me about this behavior?.
|
|
|
|
|
Buttons need to capture the mouse in order to know when the user has released the mouse button so that it can know when to act, and how to draw itself (i.e. pressed or not). If your tabs are not acting as real buttons, there is no need for the tab control to know when the mouse was released.
That is my take on it...
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I am aggree with your answer.
But its not given in MSDN that WM_RELEASEDCAPTURE will be fired only when TCS_BUTTONS style is set. Why is it so?
Can you tell me from where I can get more information on this point?
If its given in MSDN it will be more helpful for me.
|
|
|
|
|
Hi All,
Please help me with these,
I need to know the C++/COM (both included) datatypes that can hold the following types of numbers.
1. Packed BCD --> What datatype can be used to hold these numbers.
2. Packed HEX --> What datatype can be used to hold these numbers.
Please excuse if the Q's are silly, but it will be of great help if i get the answers.
Thanks & Regards,
Dhana
|
|
|
|