LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   This might be a gcc linux client error report. (http://www.linuxquestions.org/questions/programming-9/this-might-be-a-gcc-linux-client-error-report-841612/)

darkstarbyte 11-01-2010 12:40 AM

This might be a gcc linux client error report.
 
#include <stdio.h>

#define speedlimit 55
#define rate 15
#define first_ticket 85
#define second_ticket 95
#define third_ticket 100



int main()
{
int total,fine,speeding;

puts("Speeding Tickets\n");

/* first ticket */

speeding = first_ticket - speedlimit;

/* mph over the speed limit */

fine = speeding * rate;
total = total + fine;
printf("For going %d in a %d zone: $%d\n",first_ticket,speedlimit,fine);

/* second ticket */

speeding = second_ticket - speedlimit;
fine = speeding * rate;
total = total + fine;
printf("For going %d in a %d zone: $%d\n",second_ticket,speedlimit,fine);

/* third ticket */

speeding = third_ticket - speedlimit;
fine = speeding * rate;
total = total + fine;
printf("For going %d in a %d zone: $%d\n",third_ticket,speedlimit,fine);
/* This is where things get messy my total is all over the place */
/* Display total */

printf("\nTotal in fines: $%d\n",total);
return(0);
}

paulsm4 11-01-2010 12:44 AM

Maybe try initializing "total" to 0?

Just a thought :)

darkstarbyte 11-02-2010 01:32 AM

I will give a try tomorrow. I will report back if possible.

I tried the changes you proposed but they did not work.

darkstarbyte 11-07-2010 11:16 AM

Error-ed code or compiler
 
more compiled odd code

#include <stdio.h>

#define distance 378921.46
#define speed 140

int main()
{
float duration,days;

duration = distance / speed;
days = duration / 24;

printf("The moon is %f km away.\n",distance);
printf("Traveling at %f kph, ",speed);
printf("it would take %f hours to drive to the moon.\n",days);
printf("That's %f days.\n",days);
return(0);
}

theNbomr 11-07-2010 01:11 PM

You've posted 2 pices of source code (none in [Code ] tags), but haven't said anything about them. Is there a question here?

--- rod.

John VV 11-07-2010 08:36 PM

it almost looks like homework???

darkstarbyte 11-08-2010 06:04 PM

/* Sorry I thought I did say what was wrong. */

So when I compiled the code my answer on some of them are all over the place. On the first code it was the variable that was total and the second one the same except it was not called total.

wje_lq 11-08-2010 09:19 PM

Homework assignments such as this one were made obsolete when Einstein came along.

A cop pulls over a physicist, see, and says: "Do you have any idea how fast you were going?"

And the physicist, of course, says, "No, but I know exactly where I was."

John VV 11-08-2010 10:42 PM

IF you posted the error ...
That would have been VERY helpful
ALSO just HOW you ware trying to build it
-- the full build line and the FULL error--
for example
the FIRST post ( saved as "test.c" using gcc 4.1 )
Code:

gcc -o test test.c
NO ERROR ( and runs just fine )

if this c was saved as test.cpp ( c++)
this error ( gcc 4.1)
Code:

gcc -o test test.cpp
/tmp/ccWq2Ej2.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

SO with out KNOWING just WHAT YOU DID
we can NOT HELP !!!
We DO NOT KNOW how you tried to build it !!!
and yes this dose look like something from a text book .


All times are GMT -5. The time now is 12:52 PM.