Hello. I've just begun learning C and I've been practicing a few user input - calculation output programs. I got one program down that's doing fine... but I have one piece of code that's making me wonder if I'm missing something or if it's the compiler.
First, here's the code:
Well that's pretty much it. File generates fine, user input values come out fine. The only problem is that when I take a look at the RESULT.TXT file, the calculations become messed up.
#define bleacher 5
#define rsrvd 8
#define box 12
void main (void)
fileout = fopen ("A:RESULT.TXT","w");
printf ("\nPlease type in the number of bleacher seats sold: ");
printf ("\nPlease type in the number of reserved seats sold: ");
printf ("\nPlease type in the number of box seats sold: ");
printf ("\nYou have entered %d bleacher seats, %d reserved seats and %d box seats.", bleachnum, rsrvnum, boxnum);
printf ("\n \n");
printf ("\nReport created at A:RESULT.TXT.");
bleachrev = bleacher * bleachnum;
rsrvrev = rsrvd * rsrvnum;
boxrev = box * boxnum;
totalrev = bleachrev + rsrvd + boxrev;
fprintf (fileout, "\nThe bleacher seats generated $%d.", bleachrev);
fprintf (fileout, "\nThe reserved seats generated $%d.", rsrvrev);
fprintf (fileout, "\nThe box seats generated $%d.", boxrev);
fprintf (fileout, "\nThe total revenue for the game is $%d.", totalrev);
BTW, I have inputed 5000, 7000, 8000, respectively, for all the values it asks.
For example, the line "box seats generated", it would say it generated $-1200. While the lines for bleacher and box seats would calculate fine. Also, the total revenue line would also have a negative result.
I tried this using Miracle C compiler for Windows.
I then tried compiling it under LCC-WIN32 compiler. This one compiled a little better. All the calculation result showed up correctly except the total revenue value was messed up. It gave some obscure number, 62098... which is questionable since theres no way the formula
totalrev = bleachrev + rsrvd + boxrev
would generate that number after inputting 5000, 7000, and 8000.
Anyways, is the code fine? Compiler gone mad?
Any recommendations on what Compiler I should use? I know alot of people recommend Linux compilers but I know just about nothing in operating Linux, atleast for now. Thanks.