Join 137,176 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,388 people online right now. Registration is fast and FREE... Join Now!
printf("Enter an integer: "); scanf("%d", &x); printf("Enter another integer: "); scanf("%d", &y);
printf("The higher number is %f\n", higher_num(x, y));
return(0); }
int higher_num(int x, int y) { return( if (x > y) printf("%f\n", x); else printf("%f\n", y); )
}
ok... i dunno where im going wrong. the question is: Write a program with a function (give it a meaningful name) that takes as parameters two integers and prints the larger integer with a meaningful message. In main, use scanf to get two integers from the user and pass them to your new function. Hint: test the function by calling it from main on two integer constants - after you know it works correctly, add the scanfs.
i think i have it right.. but apparently its wrong..
printf("Enter an integer: "); scanf("%d", &x); printf("Enter another integer: "); scanf("%d", &y);
printf("The higher number is %f\n", higher_num(x, y));
return(0); }
int higher_num(int x, int y) { return( if (x > y) printf("%f\n", x); else printf("%f\n", y); )
}
ok... i dunno where im going wrong. the question is: Write a program with a function (give it a meaningful name) that takes as parameters two integers and prints the larger integer with a meaningful message. In main, use scanf to get two integers from the user and pass them to your new function. Hint: test the function by calling it from main on two integer constants - after you know it works correctly, add the scanfs.
i think i have it right.. but apparently its wrong..
You can't really do that in the return statement of that function. I think this is what they are actually asking for:
your function higher_num's return type is int but it doesnt returns anything?? i think you can make it void rest is all correct i just read in earlier post that system("PAUSE") is heavy in computation wise and should be avoided instead cin.get can be used to pause the screen??
This post has been edited by brainy_creature: 8 Jul, 2008 - 04:49 AM
I would actually advise using the system(); function at all costs... Take a look at the pinned topic, "holding the execution window open" here in the C/C++ forum for alternatives to "pause"
Why I advise against it:
Only works on systems that have "pause" as a system shell command
Takes more processing than alternatives:
Pauses the Program
Opens the system shell
Calls the actual shell command passed to the system function
Closes the shell
Continues the program
Now, you could get some identical results using other methods, which take nowhere near as much processing than calling system()
Though system uses a lot of processing power, it also has its uses for stuff other than pausing the window.
As much as I like to hammer on gabehabe, his code is the best snippet suggested so far (no offense everyone else).
If i'm not mistaken, isn't cin.get c++, not c?
BTW: You never checked it against integer constants like your instructor said. Before any of your output wouldn't you have to use : printf("The higher number between 1 and 2 is: %d\n", higher_num(1,2));