Uber-N00B question

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2004
Posts: 7
Reputation: SeijuroHiko is an unknown quantity at this point 
Solved Threads: 0
SeijuroHiko SeijuroHiko is offline Offline
Newbie Poster

Uber-N00B question

 
0
  #1
Jun 12th, 2004
First off I'd like to say hailz to you all! I'm your newest newbie trying to get a good grasp of programming C/C++/C#. Unfortunetly, I've got a loooong ways to go. With your help, I know I can make it.

My first question is rather tricky.... well... for me...

I'm using Mac OS X 10.2.6 on Project Builder, just doing Foundation C, but when I use scanf, it never seems to work quite right...

http://uploader.unrealboards.com/upl...canf probs.jpg

So my question is: why in the world is it asking for the scanf values before displaying my printf functions? How do I correct this?
God I'm such a newbie! :cry:
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 217
Reputation: marceta is an unknown quantity at this point 
Solved Threads: 0
marceta marceta is offline Offline
Posting Whiz in Training

Re: Uber-N00B question

 
0
  #2
Jun 12th, 2004
get a PC!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 7
Reputation: SeijuroHiko is an unknown quantity at this point 
Solved Threads: 0
SeijuroHiko SeijuroHiko is offline Offline
Newbie Poster

Re: Uber-N00B question

 
0
  #3
Jun 12th, 2004
:rolleyes:
God I'm such a newbie! :cry:
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,040
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 125
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Uber-N00B question

 
0
  #4
Jun 12th, 2004
Please only offer helpful suggestions. I'm confused - when you run the program, the 2 and 5 are printed to the top of the screen automatically? Or did you enter them, or?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Uber-N00B question

 
0
  #5
Jun 12th, 2004
he is saying that he entered them and it asks for them when he starts instead of after the print out. let me try my hand with the code for a bit and ill see if i can help out. (not likely but ill try )
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Uber-N00B question

 
0
  #6
Jun 12th, 2004
  1. /////////////////////////////////////////////////////
  2. ///program that takes one value a and places/////////
  3. ///it to the power of another value b, defining//////
  4. ///the power function by c///////////////////////////
  5. /////////////////////////////////////////////////////
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9. int main()
  10. {
  11. int a; // defining the integer a which will be to the power of b
  12. int b; // defining the integer b which will be the integer being raised to some power
  13. int c; // defines the power function used to put a to the power of b
  14.  
  15.  
  16. printf("Welcome\nThis Program takes user-defined numbers\n(a and b respectivly), and puts 'a' to the power of 'b'\nPlease enter your value of 'a' below:\n");
  17. scanf("%i", &a);
  18. printf("\n\nGood, now enter your value for 'b':\n");
  19. scanf("%i", &b);
  20. printf("\n\nCOMPUTING");
  21. c = pow(a,b);
  22. printf("\n\nThe value of %i^%i is %i", a, b, c);
  23. return 0;
  24. }

ok so heres what i wrote and it works perfectly fine, you have to have some kind of pause or break between the scanf and c=pow or else it will give you 1^12345678..... and so and so forth. also you should comment your work more so its easier to read, its a good habbit to get into, and it will pay off in the long run.

try not setting your variables to anything IE dont set int a to anything if you know that your going to define it later in the code.

also, its good practice to space your code out so that it is readable.

IE x = "some value"
Not
x="somevalue"

its easier to read the first one over the second one.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 7
Reputation: SeijuroHiko is an unknown quantity at this point 
Solved Threads: 0
SeijuroHiko SeijuroHiko is offline Offline
Newbie Poster

Re: Uber-N00B question

 
0
  #7
Jun 12th, 2004
Well, I plugged in your code, Killer_Typo, and it's still doing the exact same thing... it won't come up with anything until the 2 variables are defined by the user. I tried using breakpoints, but my newbie butt doesn't even know what those are for, so of course it doesn't work... how do you implement a break or a pause?

Sorry the code is sloppy, I just cranked it out real quick having fun and testing what *little* I know. I wasn't planing on having to post it online to get it fixed...

Man this compiler is weird! Talk about non-linear thinking!

When my programs go beyond 25-30 lines, I'll start noting the code.
God I'm such a newbie! :cry:
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Uber-N00B question

 
0
  #8
Jun 13th, 2004
i didnt have any break points, the code up there is exactly what i compiled and ran, and it worked great. are you running this from the command prompt? or macs version of it at least? i use windows so im not sure what your problem with it is. maybe someone with a mac can help you better.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Uber-N00B question

 
0
  #9
Jun 13th, 2004
Hey I think you guys are barking up the wrong tree.

scanf() works with options you sepecify.By options I mean all the stuff you specify in the " ".So it also means you can have multiple options too.

  1. some options
  2. -------------
  3. %s string (char *)
  4. %d int
  5. %f float

you can also use scanf() like this ie how to specify multiple options

  1. scanf("%d,%f",int_val,float_val);

Helps???
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,349
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Uber-N00B question

 
0
  #10
Jun 13th, 2004
Ah, yes, scanf. Trouble is almost guaranteed until you decide to quit using it.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC