| | |
Uber-N00B question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2004
Posts: 7
Reputation:
Solved Threads: 0
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?
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:
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?
C++ Syntax (Toggle Plain Text)
///////////////////////////////////////////////////// ///program that takes one value a and places///////// ///it to the power of another value b, defining////// ///the power function by c/////////////////////////// ///////////////////////////////////////////////////// #include <stdio.h> #include <math.h> int main() { int a; // defining the integer a which will be to the power of b int b; // defining the integer b which will be the integer being raised to some power int c; // defines the power function used to put a to the power of b 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"); scanf("%i", &a); printf("\n\nGood, now enter your value for 'b':\n"); scanf("%i", &b); printf("\n\nCOMPUTING"); c = pow(a,b); printf("\n\nThe value of %i^%i is %i", a, b, c); return 0; }
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!
•
•
Join Date: Jun 2004
Posts: 7
Reputation:
Solved Threads: 0
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.
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:
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!
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.
you can also use scanf() like this ie how to specify multiple options
Helps???
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.
C++ Syntax (Toggle Plain Text)
some options ------------- %s string (char *) %d int %f float
you can also use scanf() like this ie how to specify multiple options
C++ Syntax (Toggle Plain Text)
scanf("%d,%f",int_val,float_val);
Helps???
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
![]() |
Other Threads in the C++ Forum
- Previous Thread: Advantages of C++ SAFEARRAY: Explain
- Next Thread: NOOB question , graphical tiles
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







