From: "Nite Hawk" Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbies need help too! Date: Sun, 20 Feb 2000 21:06:45 -0500 Organization: Info Avenue Internet Services Lines: 92 Message-ID: <88q6gf$8pk$1@news3.infoave.net> References: <88q38n$6cf$1 AT news3 DOT infoave DOT net> <38B09C3B DOT 58B9B2E7 AT ou DOT edu> NNTP-Posting-Host: dial-28.r5.gabrlt.infoave.net X-Trace: news3.infoave.net 951098703 9012 207.144.163.158 (21 Feb 2000 02:05:03 GMT) X-Complaints-To: usenet AT news3 DOT infoave DOT net NNTP-Posting-Date: 21 Feb 2000 02:05:03 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Thankyou so much! The reason I posted it here is because you guys are all my DJGPP user buddies! :P heh -- ----------------------------------------------------- Go visit the United Fighters clan now! http://unitedfighters.hypermart.net David Cleaver wrote in message news:38B09C3B DOT 58B9B2E7 AT ou DOT edu... > > > Nite Hawk wrote: > > > > Ok so i'm a newbie but please help me out! Here is 2 problems I'm having > > (god is this embarassing!) > > 1. when I try to divide "taxPercent/100" it's value turns out to be "0" (I'm > > dividing a whole # such as 6 by 100 to get .06) > > 2. How do I get a variable to contain a name? (I'm trying to get a name as a > > variable, is this possible?) > > > > I'll explain what I'm doing in #2 better: > > I'm using... > > int yourName; > > but when the person enters his/her name it only shows the first letter of > > that persons name and also it will end the program without letting you enter > > the other variables in. > > > > Please help me!!!!!! > > thankyou so very much and please do not laugh at my ignorence! > > > Hey, we were all newbies once! I feel like a newbie myself, but I do > know the answers to your questions so here we go: > > 1) When you write "taxPercent/100" you are doing an "integer-divide" > operation. This means that only the integer value (0) is returned and > the fractional part (.06) is discarded. So, you have a few options open > to you for a solution: > But first a question, What are you storing "taxPercent/100" into? > The reason I ask is, if you are storing it in an "int" then you will > never be able to get .06 stored there. You must use a float or a double > variable to store "taxPercent/100". Now that you are storing into the > correct variable, you have a couple of options open to you: > for example, your program could look like this... > > int taxPercent = 6; file://this is your given value > float myvariable = 0; > myvariable = (float)taxPercent/(float)100; > > When you put "(float)" in front of a variable, that tells the program to > try and treat the variable as a "float" type. This is called casting. > In this example we are casting an int to a float. Float's are the > variables that let you use decimal points, ie 0.06. > > > > 2) First off, as you know, int is not the correct type to hold a > string. The varible that will hold strings is an array of characters. > Strings and character arrays are basically the same thing. Here is an > example of reading in a string from the command line (while the program > is running): > > char name[40]; > > scanf("%s", &name); > > The first line allocates memory for a variable that can hold 40 > characters, ie a string of 40 characters. > The second line reads the your input and puts it into the variable > "name". > > I hope this helps you in your endeavors. If you have any more questions > please feel free to ask. > > Some people might tell you that this is the wrong group to post this > kind of question in, and they'll probably be pretty blunt about it too. > However, I'll tell you that usually questions relating to a specific > language belong in comp.lang.c or whatever language it is you are asking > about. > > Have fun programming! > > -David C.