First off this is a pretty simple assignment. Your problem is not in your use of the pow() function but in the variable types and specifiers used in the program. They are not all consistent with each other.
(1) You declared your variables
x,
y, and
z as
doubles not
long int as your original post said the assignment calls for.
(2) Your scanf's from the original post should be
scanf("%ld",&x);
or
scanf("%li",&x);
for
long int
and
scanf("%ld",&y);
or
scanf("%li",&y);
to match the changes in (1).
(3) The specifiers (%d's) in your final printf() statement do not match your original requirements of using
long int variable declarations.
Your original code line is
printf( "%d to the power of %d is %d\n",x,y,z);
and means all of the variables will be printed to the screen as
int, but you originally declared them as
double. They should be
long int. To follow the guidelines of the assignment, you should change the line to read like this...
printf( "%ld to the power of %ld is %ld\n",x,y,z);
or
printf( "%li to the power of %li is %li\n",x,y,z);
Just like the scanf's above. Pay careful attention to the use of specifiers in the printf/scanf functions. In the future remember that mixing and switching types of variables can lead to loss of data. Make sure your input, output, and calculations all are consistent with your variable type declarations!!
Also are you programming in c or c++. It makes a difference as to whether you use printf/scanf or cin/cout respectivley. I would assume you are starting in C not C++ which is why the cin/cout statements are in the back of your book!! Stick with the printf/scanf functions until they are properly introduced by your instructor so you don't get yourself confused. Also if you are using C you should use
1 2
|
#include <stdio.h>
#include <stdlib.h>
|
in the pre-processor directives, unless the header file
#include <stdafx.h> is covering the requirements these originally would. Standard Input Output <stdio.h> and Standard Library <stdlib.h> are exactly what they sound like, pretty standard for most simple programs like this, and should help remedy some of the problems. Add these changes to the original code ad see what you get.