|
The program works, but the calculation is wrong. The is written in C. Could someone tell me what I am doing wrong?
Thank You
#include "stdafx.h"
#include <math.h>
#using <mscorlib.dll>
using namespace System;
// Function prorotypes
void sphere_volume (double);
// PI is a constant
const double PI=3.14159;
int _tmain()
{
// Integer local to Main to store initial radius value
double r;
printf("Please Enter A Positive Radius Value\n");
scanf("%lf", &r);
// If Else Function To Make Sure The User Types A Positive and Not A Negative Integer.
if (r >= 0)
sphere_volume (r);
else
printf("You Must Enter A Positive Integer!!!! Not A Negative Integer!!!\n");
return 0;
}
// This Is The Fnction That Does The Calculations For The Volume.
void sphere_volume (double radius)
{
double radius_cubed;
double exponent=3;
double volume;
printf("This Is The Test To See If R Was Passed To The Function: %lf\n", radius);
radius_cubed=pow(radius, exponent);
volume=(4/3)*PI*radius_cubed;
printf("The Volume Of The Sphere is %lf\n", volume);
}
Joseph L. Gelsomino
|
|
|
|
|
Try changing the 4/3 to 4.0/3.0 so the calulation is done as a double not as an integer, which is currently losing you the 0.3333333
If you vote me down, my score will only get lower
|
|
|
|
|
In addition to Roger's suggestion, I suggest the following to help 'polish' your application:
WackoWolf wrote: // Integer local to Main to store initial radius value
double r;
Comment (int) does not match code (double).
WackoWolf wrote: if (r >= 0)
Use a double constant (0.0) here.
WackoWolf wrote: printf("You Must Enter A Positive Integer!!!! Not A Negative Integer!!!\n");
Again referencing integers.
WackoWolf wrote: double exponent=3;
Use a double constant (3.0) here.
WackoWolf wrote: void sphere_volume (double radius)
Another suggestion I might make, although it has no impact on the outcome of your program, is to make this function's parameter const .
void sphere_volume( const double radius ); This ensures that your code does not accidently change the value of the parameter.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hello,
I am hosting an activeX control that has its own UI using standard MFC controls. I have a button that has an accelerator key ("&Browse") but the button is not responding to alt+b.
I don't know what the problem is. Perhaps the accelerator message is going to the hosting application and not the activeX control? The accelerator key never works, even when a control in the activeX control has the focus.
Any ideas?
thanks!
-Ian
|
|
|
|
|
I'm getting a strange problem that I don't know how to find out what is causing the problem. It's late in this programs' development and I can now use it for it's actual intended purpose instead of testing functionality. After I run it for a while, it slows down and I click Stop in VS. A lot of these come up in the debugging output window:
First-chance exception at 0x7c81eb33 in myprogram.exe: Microsoft C++ exception: CResourceException @ 0x0012f660. Warning: Uncaught exception in WindowProc (returning 0). I know how to handle exceptions but I don't know how to find out where the exception occurs so I can either fix it or catch it and then handle it properly.
|
|
|
|
|
Are there any localization tools which would indicate a resource in one language to change when the same resource id is updated in another language in the same RC file?
Jim456
|
|
|
|
|
Okay, a little problem here, im doing the following code, all in the same scope:
char* data;
...
data = (char*)malloc(sizeof(char));
memset( data, 0, sizeof(data) );
...
if( data != NULL )
{
free(data); // error here
data = NULL;
}
And i get a debug error, "DAMAGE: after Normal block(#371) at 0x0037F9B0."
Any ideas why im getting this?
|
|
|
|
|
Also, at the point where free(data) is called, data = 0xcccccccc.
|
|
|
|
|
Your problem:
// This allocates ONLY 1 byte, why you try to allocate only 1 byte??
data = (char*)malloc(sizeof(char));
// However this is memsetting 4 bytes which is whats causing the problem...
memset( data, 0, sizeof(data) );
// Code should read, only set up 1 byte
memset( data, 0, sizeof(char));
|
|
|
|
|
wow, dumb error, thanks alot.
|
|
|
|
|
Have you considered using new/delete instead?
|
|
|
|
|
memset( data, 0, sizeof(*data) );
|
|
|
|
|
Hi,
I work on a large App created using C++ in VS6. We have since moved to .Net and our code is unmanaged. Several of our dialogs have an overwhelming number of controls. I have been tasked to create a wizard which will walk the user step-by-step through completion of the dialog. The current dialog must stay in tact while the wizard will break the dialog into smaller "user friendly" chunks with explanation text. The idea is to have only the current dialog for experienced users and the wizard for new users. The user will have to add text to edit boxes and select from combo boxes etc. I have to do this for several dialogs. I'm trying to figure out the best way to do this without duplicating work. I'm toying with the idea of using a property sheet.
Suggestions??
Thanx
Cubzfan
|
|
|
|
|
The EnumProcesses function in the PSAPI library enumerates processes. Unfortunately, it does not include in that enumeration processes run by other users. Does anyone know of a way to enumerate all the processes in the system?
Software Zen: delete this;
|
|
|
|
|
probably you can do it only if you have admin rights.
-prakash
|
|
|
|
|
Thanks for your response.
In this case, administrator rights doesn't appear to help (the logged-in user is an administrator).
I've found an alternate method of resolving my issue (it involves an installer for a service that runs under a separate account) using the service control manager directly.
Software Zen: delete this;
|
|
|
|
|
Gary Wheeler wrote:
Does anyone know of a way to enumerate all the processes in the system?
Hi Mr. Gary,
you can try CreateToolhelp32Snapshot(..),Process32First and Process32Next api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks for your response. I'll keep it in mind.
I've found an alternate method of resolving my issue (it involves an installer for a service that runs under a separate account) using the service control manager directly.
Software Zen: delete this;
|
|
|
|
|
Hi,
I am a bigner in VC++ programming (started lerning only in March 2005 with visual stdio 6).
I request some help.
I have created a small database related application for a friend using CDAORecordSet. I made the data connection to Access (ie data is stored, added to and retrived from an access file and displaed on to a listView). I build the application seting the build configuration as 'release'. Then I copied the exe file and the access file on to my friend's computer and tried to run it.
I get the message "Unable to initialise DAO/jet engine".
Please tell me what to do now? Do I have to incorporate the jet engine in the program. If so, how do I do it? Or is there something else that must be done, like create a setup file.
Please, someone, tell me what to do? I really need some help.
Thank you,
Tara
|
|
|
|
|
You have to check register "HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\3.5\Engines exists"
If you don't have this fold you have to install Jet Engine. It's depend on OS you can get download in this site http://www.microsoft.com/downloads/results.aspx?productID=&freetext=Jet%204.0%20Service%20Pack&displaylang=en[^]
One more thing is before check DAO/Jet infromation
bool DAOInstallCheck()
{
HKEY hRet;
bool bBool=false;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Jet\\3.5\\Engines",
0,KEY_QUERY_VALUE, &hRet) == ERROR_SUCCESS)
{
bBool = true;
RegCloseKey(hRet);
}
return bBool;
}
if DAOInstallCheck())
// Message Return Install require
else
// DAO already Install
Have a nice day
-- modified at 17:22 Wednesday 12th October, 2005
|
|
|
|
|
Hi,
I'm trying to show a bitmap image (blended) over a background video using VMR9, this works fine...
Except,
The bitmap is only visable in the areas of the client window which the video is covering. (as the video is letterboxed).
Is it possible to allow the overlay bitmap to fill the entire window...
And if not, what over approach should I be looking for to acheive this?
Thanks...
Simon.
|
|
|
|
|
ooook... figured it out
I've turned off letterbox mode, and manually resized the video itself into the client area, this allows the VMR to render the bitmap to the entire client area....
Thanks for listening
|
|
|
|
|
Thanks for letting us know the solution - I sometimes look here to see common problems (and solutions) that people come across.
Elaine
The tigress is here
|
|
|
|
|
Hi,
My clients like to see the texts instead of the dimmed texts on disabled controls such as check box, radio button, combo box, and edit box in a C++/MFC dialog box. The texts on enabled controls are black.
In order to differentiate disabled controls from enabled controls (black texts), I would like to add some color (blue) on the disabled control texts.
Can you tell me the existing or potential solutions?
Thank you very much!
Shelley
-- modified at 16:20 Wednesday 12th October, 2005
|
|
|
|
|
y22zhou wrote:
My clients like to see the texts instead of the dimmed texts on disabled controls such as check box, radio button, combo box, and edit box in a C++/MFC dialog box.
This would seem to be counterintuitive. For example, say you set the text of these disabled controls to red, and the user went in and changed their theme to display red text for controls. How would they differentiate between a disabled control and an enabled control?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|