If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

selection

Dear sir

I am write a program to ABC County (county code A) has a 7 percent sales tax rate; the rest of the state is 6 percent rate. I want to print out the amount owed on purchase including sales tax, but my output is displayed as below:

Sorry for correcting you, but fflush(stdin) can invoke undefined behaviour you can use while (getchar() != '\n'); instead. void main can also produce undefined behaviour so use int main() and put return 0; at the end of your program
About your program, this might help you a bit

Originally posted by maes I don't want to be an ******* for correcting you, but fflush(stdin) can invoke undefined behaviour you can use while (getchar() != '\n'); instead. void main can also produce undefined behaviour so use int main() and put return 0; at the end of your program
About your program, this might help you a bit

Well first of all watch your language in our forums.

Second of all you better know what you are talking about before correcting someone. Using void main() is fine as long as it is part of the language of the particular compiler that you are using. And yes there is more than one C++ compiler, quite a few actually. Using void main() was how main was declared in C but in C++ depending on which compiler you use it can be declared as void main() or int main(). I imagine that Xiang is using a compiler that accepts void main() since obviously he has compiled and ran his program already but just didn't get the output he wanted.

First of all sorry for the language, but it wasn't meant to be disrespectfull. I also have been corrected when I made a reply, and I felt that the person who corrected me was a , well you know. I didn't want him/her to feel the same way about me, that is why I said it. If you or him/her took it the wrong way, then I'm sorry, I apologize.

Second, using void main isn't right. Not because the compiler allows it, that doesn't mean it is right.
C99 standard:

5.1.2.2.1 Program startup

1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;9) or in some other implementation-defined manner.

I agree that it doesn't explicitly say: "you can not use void main()"
But "It shall be defined with a return type of int" is good enough for me.

is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }

and
int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it