When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
12 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
!f
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, k;
int sum = 0;
cout << "Ievadiet skaitli: ";
cin >> n;
cout << "Ievadiet pakapi: ";
cin >> k;
/// Apgriez skaitli ///
while (n > 0) {
int num = n % 10;
int pakape = pow(num, k);
sum = sum + pakape;
cout << "pakape: " << pow(num, k) << endl;
n /= 10;
cout << "n: " << n << endl;
cout << "num: " << num << endl;
cout << "sum: " << sum << endl;
}
if (sum == n)
cout << "Ir";
else
cout << "Nebus";
return 0;
}
Input: 153
Input #2: 3
Expected output: "Ir"
First loop is okay, but when 5^3 = 125 and you add the number to the sum, for some reason it removes 1
(27+125=152) but in the code it adds both numbers and the sum is 151, in the first loop it didnt do that.
uh oh it wasn't supposed to delete the original message
I'll fix that
anyway, have you tried stepping through your code in a debugger?
yeah, in online it showed correctly but in codeblocks it didnt, i figured it out though. It was because of digits behind comma. I replaced int with double and got fixed.
!solved
no problem ๐
!solved