Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Okay, here's the deal. I'm having trouble with one aspect of my program. It's basically a series of prompts. They all work fine until I get this:
Enter the depreciation type:Enter the total value of all buildings:$
At the first ":" the program isn't pausing to accept a character for depreciation type, it's just jumping to the next prompt. Here's the applicable code:
(From ReadData Function)
printf ("Enter the depreciation type:");
scanf ("%c",deptype);
printf ("Enter the total value of all buildings:$");
scanf ("%f",buildings);The variables are declared in my main function:
float buildings;
char deptype;The same thing is happening later in my program again with a prompt that's supposed to read a single character. Any help is appreciated.
BTW- The program compiles and gives warnings that i'm using certain variables before their value is set, but it's not these variables that are affected.

Try doing this:
(From ReadData Function)
printf ("Enter the depreciation type:");
scanf (" %c",&deptype);
printf ("Enter the total value of all buildings:$");
scanf ("%f",&buildings);Adding that space in front of the %c will flush out the erronious data that is being put into deptype. Also, you need a & in front of the variable names.

Perfect, thanks. I didn't need the &'s because I'm not passing the value back to the main function, I'm just using it in the ReadData function. But your adding a space thing worked perfectly. My prof may wonder how I knew that, but oh well. :)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |