0
What is wrong with this code?
I was trying to make exponentation, "wynik" means "result" in my language. "Wynik to" means "The result is". The problem is that when i run the code the result always equals 0. Why? #include <iostream> using namespace std int main() { int a,b, wynik; cin >> a; cin >> b; for(int i=1; i<=b; b--) { wynik*= a; } cout << "Wynik to: " << wynik; return 0; }
5 Answers
+ 3
if you initialize wynik with 1, it seems to work.
int a, b, wynik=1;
If you use a variable although you haven't given a value to it yet, strange stuff happens.
+ 2
Oh i forgot. Thanks for helping.
0
Without seeing the code we can't help you.
Care to share?
You can upload it in Code Playground and link it here!
0
Can you show us your code (code playground)?
0
I showed the code in description but i can copy it again
#include <iostream>
using namespace std;
int main() {
int a,b, wynik;
cin >> a;
cin >> b;
for(int i=1; i<=b; b--)
{ wynik*= a;
}
cout << "Wynik to: " << wynik;
return 0;
}