|
Ev3nflow wrote: printf("\n\n\t\tInterest rate %20d", taxrate);
printf("\n\n\t\tInterest added %20d",interest);
printf("\n\n\t\tTax deducted %20d", tax);
Why are you not using the %f format specifier?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Well, he did define interest and tax to be int. Why? I don't know.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Ev3nflow wrote: #include;
The include statement needs a filename to include, such as:
#include "file1.h"
or
#include <file2.h>
[modified]
Nevermind, I see what happened to the filename. The HTML gods ate it.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi thanks to all who have help me. I have changed my code, and it seems to compile but I still get a warning 14 [Warning] converting to `int' from `float' I have pasted my code below
#include <stdio.h>;
const float lowrate=2;
const float highrate=5;
const float taxrate=20;
int balance,threshold,total,interest,tax,taxed,Y,is;
main()
{
printf("\n\n\t\tInput account balance ");
scanf("%d",&balance);
if (balance<threshold)
interest=balance*lowrate/100;
else
interest=balance*highrate/100;
total=balance+interest;
if (taxed) is; 'Y';
tax=interest*taxrate/100;
total=total-tax;
getchar();
printf("\n\n\t\tInterest rate %20d", taxrate);
printf("\n\n\t\tInterest added %20d",interest);
printf("\n\n\t\tTax deducted %20d", tax);
printf("\n\n\t\tTotal account balance %17d",total);
getchar();
}
|
|
|
|
|
It does not appear that you have changed anything.
Ev3nflow wrote: #include ;
We know what it is, but still.
Ev3nflow wrote: if (balance < threshold)
threshold has not been initilized.
Ev3nflow wrote: interest=balance*lowrate/100;
I would suggest using 100.0 instead.
Ev3nflow wrote: if (taxed) is; 'Y';
This does not compile.
Ev3nflow wrote: printf("\n\n\t\tInterest rate %20d", taxrate);
printf("\n\n\t\tInterest added %20d",interest);
printf("\n\n\t\tTax deducted %20d", tax);
You are still using %d .
To make your code easier to read, highlight it all and click the "code block" button. Then click the "Preview" button to make sure it looks like something others can decipher.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I am using MFC dialog application and I have some global variables.
I am struggling with where and how I can declare an external function to make initialization for external or global variables and this function should bring the values from DB to store them in those global variables.
I tried to put the desired code without include them inside function structure after the ProjectNameApp theApp in the ProjectName.cpp// but failed
I tried to put the function declaration as a member function in the ProjectNameApp class and call it after the ProjectNameApp theApp in the ProjectName.cpp //but failed as well
I tried to put the function declaration as a member function in the ZZ.cpp and made the proper including //but failed and inform me that you can't initialize them into closed scope.
it seems to me that the initialization should be in the test.cpp and without function using. I don't believe that but how I can make it.
Please any one can help me?
Any help will be appreciated
|
|
|
|
|
Personally I usually put all variables that would be global into the Application class instead. So initialization of global variables would be either in InitInstance or in the application's constructor. But that's me.
But I think that the same idea would apply: initialize the globals using the application's constructor, or in InitInstance. That way it's out of the way before you access the variables later in the program.
|
|
|
|
|
class CYourApp : public CWinApp
{
....
public:
float m_Yourvariable;
public:
void YourFunction();
...
}
In the ZZ.cpp file:
extern CYourApp theApp
access your global variable ---> theApp.m_Yourvariable;
access your global function ---> theApp.YourFunction();
|
|
|
|
|
Global variables must be defined in a .cpp file. You may initialize them wherever you want.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for all of you.
Anyway Itried to make initialization in Initinstance and the project's constructor but its not working always give me an unresolved variable.
Its work fine when Iam access my variables and functions via theApp, but I should include the "ProjectName.h" in each function i want to use the variable there not like the extern int x(for example). So I am not sure if these variables will reserved its values during the cycle of system.
anyway I will test it. and thank you again for all of you.
Regards,
|
|
|
|
|
Thank you for all of you.
Anyway Itried to make initialization in Initinstance and the project's constructor but its not working always give me an unresolved variable.
Its work fine when Iam access my variables and functions via theApp, but I should include the "ProjectName.h" in each function i want to use the variable there not like the extern int x(for example). So I am not sure if these variables will reserved its values during the cycle of system.
anyway I will test it. and thank you again for all of you.
Regards,
|
|
|
|
|
I know that there's a method,
C++
UINT MsiInstallProduct(
__in LPCTSTR szPackagePath,
__in LPCTSTR szCommandLine
);
However, it needs a package path, how can i get it by product code?
Thanks!
|
|
|
|
|
when I updating excel file using odbc driver I got the following exceptions frequently When I click on any cell
Key violation.
[Microsoft][ODBC Excel Driver] The connection for viewing your linked Microsoft Excel worksheet was lost.
Key violation.
[Microsoft][ODBC Excel Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened
General SQL error.
exclusively by another user, or you need permission to view its data.
how can I prevent to avoid these exceptions
Trioum
|
|
|
|
|
You can run your program under the debugger to understand the nature of these exceptions and then fix your code.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
How Can I fix the following error
Trioum
|
|
|
|
|
Debug it. I won't be replying any further on this thread.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
in the name of god
hello
when we declare a variable in c++ as :
int x;
int x1=98;
then initialize it with a value.
how we can know that a variable has been initialized or no?is there any way (compiler can or ...)to distinguish between initialized variable and non-ini...
that we dont know the value of them.
valhamdolelah.
|
|
|
|
|
nope.
(don't take my word for it)
in DEBUG more, variable _can_ be initialized to zero (or some other default patterns) as an aid for internal debugging , but in RELEASE, they are not (for performance issues).
When compiling, I would assume the compiler is just checking if the variable was assigned something.
This signature was proudly tested on animals.
|
|
|
|
|
so how compiler knows it?
|
|
|
|
|
it could checks syntactically if the variable is on the left-hand side of an '=', of if syntactically if follows the syntax of an initializer...
for example :
int i;
i = 0;
or
int i(123);
or
class Tata
{
Tata() : m_i(123){};
int m_i;
};
Or there might be other more advanced compiler tricks to keep track of variable assignments...
This signature was proudly tested on animals.
|
|
|
|
|
in the name of god
thanks Maximilien.
i don't know it up to now.
i have also another question :you said that when we use = compiler knows that a variable is initialized so if it save any data for this?any data to know which variables are initialized if yes where?
thanks.
valhamdolelah.
|
|
|
|
|
khomeyni wrote: i don't know it up to now.
Don't know what?
khomeyni wrote: i have also another question :you said that when we use = compiler knows that a variable is initialized so if it save any data for this?any data to know which variables are initialized if yes where?
The information you are after is not available via code. It's something that the compiler handles internally.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i don't care about = ,() , ...
thanks.but indeed i want to know more ,but as it seem it is deep because of compilers.
thanks.
valhamdolelah.
|
|
|
|
|
Easy.
You created the variable, so you know if it's initialized or not. Unless you can't remember 
|
|
|
|
|
khomeyni wrote: how we can know that a variable has been initialized or no?
Looking at the code?
Ah, and the compiler warns about uninitialized variables.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|