Message-ID: <38B09C3B.58B9B2E7@ou.edu> From: David Cleaver X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbies need help too! References: <88q38n$6cf$1 AT news3 DOT infoave DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 74 Date: Sun, 20 Feb 2000 20:00:27 -0600 NNTP-Posting-Host: 129.15.140.115 X-Complaints-To: usenet AT ou DOT edu X-Trace: news.ou.edu 951098351 129.15.140.115 (Sun, 20 Feb 2000 19:59:11 CST) NNTP-Posting-Date: Sun, 20 Feb 2000 19:59:11 CST Organization: The University of Oklahoma To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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; //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.