Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andrewface

macrumors 6502
Original poster
May 17, 2006
284
56
You're setting answer to be a value that's equal to what its current value times base is. The '=' is not the algebraic equal sign, it is a sign that means "get".

ok...thanks alot that is alot clearer..

one last problem its taking the 2nd input scanf before the second printf how come?

Please enter a number:2
2
Please enter an exponent:4
q2 has exited with status 0.
 

XnavxeMiyyep

macrumors 65816
Mar 27, 2003
1,131
4
Washington
ok...thanks alot that is alot clearer..

one last problem its taking the 2nd input scanf before the second printf how come?

Please enter a number:2
2
Please enter an exponent:4
q2 has exited with status 0.
I'm actually not sure. The code looks correct, but I'm not familiar with plain C.
 

CaptainZap

macrumors regular
Jan 17, 2007
170
0
Just take out the \n in the first scanf, so it looks like this

Code:
#include <stdio.h>

main()
{
	int answer = 1, base, exponent, i;

	printf("Please enter a number: ");
	scanf("%d", &base);
	printf("Please enter an exponent: ");
	scanf("%d", &exponent);

	for (i = 0; i < exponent; i++)
	{
		answer=base*answer;
	}
	printf("%d", answer);
	printf ("\n");
	
	return 0;
}
 

andrewface

macrumors 6502
Original poster
May 17, 2006
284
56
thanks alot for your help

one last question what is the best code to use to make the window stay open at the end of the program...i used return 0, or getch() at school are those acceptable in the world of c?
 

andrewface

macrumors 6502
Original poster
May 17, 2006
284
56
heres another program i need help with for my lab tomorrow

i need to write a program that will take a string that you input and output whether or not it is a palindrome...it only has to work for simple palindromes like radar and not sentences and what not...someone gimme some insight?
 

scan

macrumors 6502
Oct 24, 2005
344
0
heres another program i need help with for my lab tomorrow

i need to write a program that will take a string that you input and output whether or not it is a palindrome...it only has to work for simple palindromes like radar and not sentences and what not...someone gimme some insight?

these are ridiculously easy and common problems. google it. I'm sure you'll find many solutions whether you like it in a for loop, recursive, while loop, etc.
 

andrewface

macrumors 6502
Original poster
May 17, 2006
284
56
these are ridiculously easy and common problems. google it. I'm sure you'll find many solutions whether you like it in a for loop, recursive, while loop, etc.

ya im finding alot of really complicated ones or C++ versions on google..i just want a bit of a head start because everyone in my class have background in programming so im always the last one sitting there trying to figure it out

anyone get me started?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.