My code isnt working even after getting the right output, please check

#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;

    string octal = "";
    while(n!=0){
        int r = n%8;
        n/=8;
        char c = r+'0';
        octal = c+octal;
    }
    cout << octal <<endl;
}

refer this

i havent been taught strings yet, is there another way we can solve this question without using strings?

u can use arrays then

can i not do it using loops only? i havent been taught arrays either

i dont think that would be possible… maybe u just go and watch 1-2 videos of array/ string and then come back to this ques…

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.