|
Fightingbee wrote:
and the compiler threw up about 7 errors at me.
What errors did you get?
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
Well ok here is the copy of the changed code,
#include<iostream>
#include<conio.h>
using namespace std;
int sum = 0;
int ssum = 0;
int msum = 0;
double dsum = 0;
int x = 0;
int y = 0;
int menu();
int c = menu();
int main()
{
do
{
menu();
if(c == 1)
add();
else if(c == 2)
sub();
else if(c == 3)
multi();
else if(c == 4)
div();
}
while(c == 5);
cout<<"Thank you for using the calculator!"<<endl;
getch();
return 0;
}
menu()
{
int sel = 0;
cout<<"Please select a menu choice..."<<endl
<<"1. Add"<<endl
<<"2. Subtract"<<endl
<<"3. Multiply"<<endl
<<"4. Divide"<<endl
<<"5. Exit program"<<endl;
cin>>sel;
if(c > 5 && c < 1)
cout<<"You have entered an invalid selection!"<<endl;
return sel;
}
int add()
{
cout<<"Please enter a number..."<<endl;
cin>> x;
cout<<"Please enter your second number..."<<endl;
cin>>y;
sum = x + y;
cout<<"The answer is "<<sum<<endl;
return sum;
}
int sub()
{
cout<<"Please enter a number..."<<endl;
cin>> x;
cout<<"Please enter your second number..."<<endl;
cin>>y;
ssum = x - y;
cout<<"The answer is "<<ssum<<endl;
return ssum;
}
int multi()
{
cout<<"Please enter a number..."<<endl;
cin>> x;
cout<<"Please enter your second number..."<<endl;
cin>>y;
msum = x * y;
cout<<"The answer is "<<msum<<endl;
return msum;
}
double div()
{
cout<<"Please enter a number..."<<endl;
cin>> x;
cout<<"Please enter your second number..."<<endl;
cin>>y;
dsum = x / y;
cout<<"The answer is "<<dsum<<endl;
return dsum;
}
And here are the errors it is throwing up,
--------------------Configuration: assign4 - Win32 Debug--------------------
Compiling...
assign4.cpp
D:\Assignment 4\assign4.cpp(33) : error C2065: 'add' : undeclared identifier
D:\Assignment 4\assign4.cpp(35) : error C2065: 'sub' : undeclared identifier
D:\Assignment 4\assign4.cpp(37) : error C2065: 'multi' : undeclared identifier
D:\Assignment 4\assign4.cpp(39) : error C2660: 'div' : function does not take 0 parameters
D:\Assignment 4\assign4.cpp(68) : error C2373: 'add' : redefinition; different type modifiers
D:\Assignment 4\assign4.cpp(81) : error C2373: 'sub' : redefinition; different type modifiers
D:\Assignment 4\assign4.cpp(94) : error C2373: 'multi' : redefinition; different type modifiers
Error executing cl.exe.
assign4.obj - 7 error(s), 0 warning(s)
|
|
|
|
|
OK First of all you should make all of your int be double.
Whats up with your spacing anyways it's like 20 spaces for a tab.
Your making it too complicated for your self. Here is what I made when I was a beginner hopefully it will teach you something.
#include <iostream>
using namespace std;
float inputOne, inputTwo, answer;
char operator_, yn;
int main()
{
while (yn != 'n')
{
cout << "First number + - / * ^ second number\n";
cin >> inputOne >> operator_ >> inputTwo;
if (operator_ == '+')
answer = inputOne + inputTwo;
if (operator_ == '-')
answer = inputOne - inputTwo;
if (operator_ == '*')
answer = inputOne * inputTwo;
if (operator_ == '/')
{
if (inputTwo == 0)
{
cout << "Cannot divide by 0";
}
else
answer = inputOne / inputTwo;
}
if (operator_ == '^')
{
answer = inputOne;
for (int i=2; i<=inputTwo; i++)
answer = answer * inputOne;
}
cout << endl;
cout << inputOne << " " << operator_ << " ";
cout << inputTwo << " = " << answer;
cout << "\n\nSolve another? <y><n> ";
cin >> yn;
cout << "\n";
}
return 0;
}
[It is possible to represent everything in this universe by using 0 and 1]
I was born intelligent
Education ruined me!.
An idea is useless until it has been implemented.
|
|
|
|
|
How could I change the Font for the Application. For the dialogs it is easy, but for my Statusbar / Menu I didn't find any good solution by now. Could anyone help ?
|
|
|
|
|
我觉得状态栏的文字给对话框的文字一样呀!你同样可以采用在对话框中的方法
下面是我的做法:
HBRUSH CXXXX::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
/************************************************************************/
if ((nCtlColor == CTLCOLOR_STATIC ))
{
pDC->SetBkMode(TRANSPARENT);
int nID = pWnd->GetDlgCtrlID();
if( (nID == CONTROL'S ID ))
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(TRANSPARENT);
//pDC->SetBkColor(RGB(255,255,255));
}
HBRUSH hbr = ::CreateSolidBrush(RGB(248,251,255));
return hbr;
}
// TODO: Return a different brush if the default is not desired
/************************************************************************/
return hbr;
}
|
|
|
|
|
The color of the Font is not important. The Font itself is. In this case I want to use Arial Unicode MS by default.
I don't want to change the Windows Settings for this.
|
|
|
|
|
for statusbar, use the SetFont member function.
Read mike dunn's FAQ first.
Hari Krishnan
|
|
|
|
|
I think I should explain :
I tried the SetFont some times at different location, everytime with the same result : 1. I don't change anything or 2. It change the Font to anything like default System Font. But I never got the Font I want.
I checked and tied several Onlinetuturial to change the Font in StatusBar, also the one in the MSDN (mainly thought for Bitmaps in CStatusBar). Everytime only this results. Cause I can use the Font in all my Dialogs (thanks to Visual Net, I could choose this in the Resource Editor), I thought there may be an easy way also for the MainFrame. That could help also with the title of the dialogs/windows (maybe).
Is there any help for me ?
|
|
|
|
|
Hi All
Not sure what this problem is called but I've stored information in an array
of integers and stuck in OnPaint an attemp to redraw the rectangles and
spots of colour using SetPixel. When I un-minimize the information ie the
drawings are not re-appearing. Am I placing the "re-draw" in the wrong
function? OnPaint sounded reasonable for Un-minimzing.
Terry
|
|
|
|
|
how is that possible to draw text contained in a Cstring object in spiral form in a SDI application in view window.Object can be accesed in OnDraw function of MFC View class.What r the function those describe the features in which we can draw characrters in any direction.
HUMAYUN AJMAL
|
|
|
|
|
Image file I suppose.
I am interested in knowing as well.
|
|
|
|
|
I think you might be able to do it using OpenGL programming.
|
|
|
|
|
the different between the framework of dll and application
in the VC++ 6.0??
a good man in china
|
|
|
|
|
YEAH,WIN32 DLL AND WIN32 APPLICATION
a good man in china
|
|
|
|
|
A dll is a dynamic link library of functions and variables that are loaded dynamically by an application or service into its address space at run time.
John
|
|
|
|
|
LOL
[It is possible to represent everything in this universe by using 0 and 1]
I was born intelligent
Education ruined me!.
An idea is useless until it has been implemented.
|
|
|
|
|
I've got a component which uses a library which MUST be properly closed when you exit from using it. It takes a couple of seconds.
Is it ok to create a Thread to do all this work (as long as I don't modify or read memory inside the component from within the thread) in the Destructor of the component? And exit the component immediately?
|
|
|
|
|
Paul Farry wrote:
Is it ok to create a Thread to do all this work (as long as I don't modify or read memory inside the component from within the thread) in the Destructor of the component?
Yes, it's fine. As you mentioned, watch out for accessing memory that has been deleted.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
I was wondering if anyone else has seen this problem:
When I right click and open up a context menu in a CWnd sub-classed dialog, then go into a submenu my mouse cursor goes from the arrow to the hourglass and never reverts back to the arrow cursor until after I close the dialog box.
It doesn't seem to matter which way I create the menu (either through resources or purely by code) and I have tried overwritting the OnSetCursor function which always sets the mouse to the arrow.
I know that OnSetCursor is being called because outside of a menu the cursor is not an arrow.
Here is the sample of my code:
for cursor override:
BOOL CCMFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (message == 0)
{
HCURSOR hCursor = LoadCursor(NULL, IDC_ARROW);
SetCursor(hCursor);
return TRUE;
}
return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
for menu creation:
CMenu mnuTop;
mnuTop.LoadMenu(IDR_POPUP_MENU);
CMenu* pPopup = mnuTop.GetSubMenu(0);
ASSERT_VALID(pPopup);
pPopup->TrackPopupMenu(TPM_RIGHTBUTTON |
TPM_LEFTALIGN, Point.x, Point.y, this, NULL);
Thank you for any insight into what could be causing this!!
Crystal
|
|
|
|
|
dWorkVan wrote:
When I right click and open up a context menu in a CWnd sub-classed dialog, then go into a submenu my mouse cursor goes from the arrow to the hourglass and never reverts back to the arrow cursor until after I close the dialog box.
Seems to mimic how Windows 2000 Explorer.exe and its Property dialog behaves - seems you are in good (or bad, depending on how you look at it) company.
Have you registered a cursor for your dialog? Do you handle all the WM_* messages as you should?
To give you a hint: The problem isn't with the manu code (no matter what it does) - the problem is with setting the right cursor when the focus returns to the dialog. If the hCursor is NULL, guess what it *can* set it (or *not* set it) to.
|
|
|
|
|
Thanks for the insight.
To answer your questions:
The cursor is registered for the dialog and its owner and I am almost positive that all the WM_* messages for both are handled correctly. Actually, the dialog the menu appears on isn't the owner of the menu, but both the owner of the menu and the dialog handle the WM_SETCURSOR messages which *should* cover the case when focus returns to the dialog.
So I am still at a loss of how to fix / overcome this problem.
|
|
|
|
|
How do I correct this error in VC++6.0?
"utils.c(125) : fatal error C1010: unexpected end of file while looking for precompiled header directive"
along with all other imported c files
I created a win32 console app "hello world" and inserted C files from
ftp://ftp.cs.brown.edu/pub/nlparser/nlparser.tar.gz
Thanks
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
You probably have either /Yu or /YX set. In Project Settings in VC 6.0, go to the C++ tab and select Precompiled Headers from the Category drop-down. Select the 'Not using precompiled headers' radio button and choose OK. It's best to do this for all project types - choose All Configurations in the Settings For drop-down before making the setting.
Precompiled headers are a way to collect common headers for your project in a single file that the compiler generates once; it can then reload a pre-compiled version of the common headers and speed up compiling each source file, because it only has to read and process the headers that source file includes that aren't in the PCH, and compile the code in the source file. You typically see that 'stdafx.cpp' takes ages to compile, then everything else takes fractions of a second on a fast machine.
The AppWizard assumes you want to do this and configures your project for /YX (automatic use of PCH) if it's an empty project, or with /Yc"stdafx.h" (create PCH through stdafx.h) for stdafx.cpp and /Yu"stdafx.h" (use PCH through stdafx.h) for all other source files.
When any of the /Y{cuX} options are specified, the compiler looks for #include "headername" , where headername is the header specified as the argument. If no argument is specified, the default name is based on the source file name (/Yc) or is MSVC.PCH (/YX). The compiler also looks for #pragma hdrstop directives. If it doesn't find either in the source file, it generates a C1010 error.
/YX creates the precompiled header only if it doesn't already exist; in practice, this means that the first source file compiled is the one which will cause the PCH to be generated. It's usually better to specify /Yc on a file which only generates the PCH, and /Yu on everything else.
--
Mike Dimmick
|
|
|
|
|
thanks that worked. but now I have 345 errors to debug
am I not supposed to compile C files in MSC++6.0
I guess the files were not meant to be converted to C++, darn I need Part of Speech tagger in C++. It will probably take me a while to figure out the errors. Thanks!
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
If the file extension is .c, and the /Tp or /TP switch is not specified, the code should be compiled as C.
In the header files, ensure there's an extern "C" block around all the function declarations, so that the compiler doesn't decorate the names, or, rather, uses the C rules for name decoration. If this happens, the linker will complain that it can't find a funny name like ?a@@YAHD@Z, which is the decorated name for int __cdecl a(char) .
This should allow your code to be written in C++, with the libraries you're using in C.
I've done this when porting a DOS application to Pocket PC, which has no console library, therefore I had to emulate a console myself. The emulation layer was written in C++, while the original application was written in, and was compiled as, C.
--
Mike Dimmick
|
|
|
|