Computing.Net > Forums > Programming > C Prog. Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C Prog. Help

Reply to Message Icon

Name: Grizzer
Date: February 25, 2003 at 08:10:19 Pacific
OS: Win 98
CPU/Ram: Unknown
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Chad
Date: February 25, 2003 at 10:07:49 Pacific
Reply:

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.


0

Response Number 2
Name: James
Date: February 25, 2003 at 11:33:52 Pacific
Reply:

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. :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C Prog. Help

Simple C++ prog help plz www.computing.net/answers/programming/simple-c-prog-help-plz/12574.html

c prog (Borland) for dos dir command www.computing.net/answers/programming/c-prog-borland-for-dos-dir-command/844.html

Help in C Prog www.computing.net/answers/programming/help-in-c-prog/891.html