![]() |
|
#1
|
|||
|
|||
noob question of % escape sequence.Hello all. I just joined and this will be my first post here at GID.
I was having a problem on getting a percent sign(%) to print in front of an escape sequence. %f is supposed to represent some percent with decimals Heres what i what i have typed. Code:
Code:
Code:
Code:
Please open my file for a more in depth view of what im trying to do. Anyway. i just got into C and am loving it. I hear its a fundamental language that will reinforce on my learning of others, which i plan to do. im really excited about it. if you would like to comment on my code, it would be my honor. i am probably not the most effiecient programmer, so any advice on condensing it or such would be great. My math isnt probably that good either, im only in 9th grade Algebra I, im not sure if the ways ive chosen are the best. Thanks |
|
#2
|
||||
|
||||
|
Your beginning of your post is confusing. When you post an example, like
Code:
Code:
Any time you use "%%" in a printf, you will print a single % symbol. So if you want the message Code:
Code:
|
|
#3
|
|||
|
|||
|
Teimu, I think what also is happening is that you don't properly attach the "%f" to the variable you want. Since the compiler doesn't see a variable attached to "%f" it leaves it as %f. The only thing I see wrong is that in your printf statement, you must include the "&" symbol, so your code should look like this:
printf(That's a %.0f%% increase.", &perg); Try that and see if it works |
|
#4
|
||||
|
||||
|
Quote:
perg should be defined as a double or float, so the & symbol is not necessary. |
|
#5
|
|||
|
|||
|
Yes, the Force is strong with me but much to learn I still have! I am still a intermediate programmer so I am still learning certain things. Okay, so maybe the "&" isn't needed, but does the space between " and the , matter. For instance, Teimu posted - printf("That's a %f increase.",perg);.....
But shouldn't he have a space like this - printf("That's a %f increase.", perg);....or does the space matter? <--- I just put this in because I thought it was funny, ![]() |
|
#6
|
||||
|
||||
|
Usually, programmers add spaces for better readability, but they are not required by the compiler. You could write an entire program in one line, but no good programmer would ever actually do that. Just to be clear, whitespace is not totally ignored. You couldn't write a function prototype like this and get away with it:
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
|
ahhh, much better. thanks WaltP ,ObiWan506, aaroncohn. really apprieciate it. works now.
however. im running into a new problem. ill post it here to save space instead of a new thread. okay. now that my percent sign shows up completely, it looks fine and dandy. i would now like the user to be able to choose if he wants to run the program again. he can, but if he types 'y' as opposed to "Y", it will determine it false, and move onto else. look at this Code:
also would you know how i would make the program go back up to the start again, if, of course the user chooses to do so. i just learned the 'for' function, but that was like Code:
|
|
#8
|
|||
|
|||
Logical operatorTry this:
Code:
If the first condition is true, then execution proceeds (the other condition is not checked). If the first is not true, then the second is checked. If the second is true, then execution proceeds. The result is that, if neither condition is true, the "else" block is executed. Dave Quote:
|
|
#9
|
||||
|
||||
|
Quote:
Dave's response about the if() is accurate. As for the loop, a do-while() loop is made for this type of true/false loop. for() loops are best used for range loops -- 1 thru 10, 'A' thru 'F', etc. At the top of the loop, simply put do. At the end add while() statement and in the parens put the expression Dave used in his if(). Then all you will need is the prompt and the character input at the end. The while takes places of the if. CPP / C++ / C Code:
|
|
#10
|
|||
|
|||
|
haha. YYEESSSSS. you all must know the feeling you get when debug some code. i didnt understand that you had to take out the else portion hanging on back there, even tho you wrote it right out for me
Quote:
|
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question of practice | magiccreative | C++ Forum | 1 | 06-Feb-2004 08:17 |
| a C input question | tmike | C Programming Language | 1 | 16-Sep-2003 03:31 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The