I had made a program which calculate and store data in form of array structure,and at the end of the code, I will find the car plate with slowest speed and greatest speed.BUT I encountered a weird output for the "find the slowest car section".
it shows somethings like this Slowest speed = 0.000000 Car = 6954000
Fastest speed = 300.000000 Car = 13 Process returned 9 (0x9) execution time : 24.881 s Press any key to continue.
//it is weird cuz the "fastest" can work but the slowest just cant//
#include <stdio.h>
struct Car
{
int plate;
float time,distance,speed;
};
int main ()
{
int n;
struct Car car[10];
int fcar,scar;
for (n=1;n<=10;n++){
printf ("\nPlate = ");
scanf("%d",&car[n].plate);
printf ("Distance = ");
scanf("%f",&car[n].distance);
printf ("Time = ");
scanf("%f",&car[n].time);
(car[n].speed) = (car[n].distance)/(car[n].time);
printf ("Speed = %f",car[n].speed);
//-----------------------------------------------------------------//
if (car[n].speed< 70){
printf("\nSlow\n");
}else if (car[n].speed>=70 && car[n].speed<110){
printf("\nNormal\n");
}else{
printf("\nFast\n");
}
printf("-----------------------------------------------------");
}
float minn = car[0].speed;
for (n=1;n<=10;n++){
if ( car[n].speed < minn){
minn = car[n].speed;
scar = car[n].plate;
}
}
printf("\n\nSlowest speed = %f",minn);
printf("\nCar = %d",scar);
float maxx = car[0].speed;
for (n=1;n<=10;n++){
if ( car[n].speed > maxx){
maxx = car[n].speed;
fcar = car[n].plate;
}
}
printf("\n\nFastest speed = %f",maxx);
printf("\nCar = %d",fcar);
}
//-------------------------------
Aucun commentaire:
Enregistrer un commentaire