#include <stdio.h>
#define NUMPLACE 3
#define NOP -1.0
//1-D array to keep track of the place names
char places[NUMPLACE] = {
'A',
'B',
'C'
};
//2-D array for the adjacency matrix representation
float roads[NUMPLACE][NUMPLACE] = {
{0.0, 3.5, NOP},
{3.2, 0.0, 2.8},
{3.1, NOP, 0.0}
};
int main(void)
{
int from;
int to;
char origin, dest;
printf("From>> ");
//Obtain the origin's place name from the user and find index associated with the place namespace
scanf("%c", &origin);
for(from=0;from<NUMPLACE;from++)
{
if(places[from]==origin)
break;
}
printf("To>> ");
//Obtain the destination's place name from the user and find index associated with the place name
scanf("%c", &dest);
for(to=0;to<NUMPLACE;to++)
{
if(places[to]== dest)
break;
}
printf("From %c to %c ", places[from], places[to]);
//Obtain the distance from the adjacency matrix.
if ((roads[from][to])!=NOP)
printf("it is %.1f km\n", roads[from][to]);
else
printf(": no direct road.\n");
return 0;
}
**Can anyone please help me to identify what is the problem of this code, I can't get the input I want. It can't display and scan the "To>>" input, why?
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
http://gsamaras.wordpress.com/code/caution-when-re...
http://stackoverflow.com/questions/13542055/in-c-h...