i started to learn C a few days ago through the cs50 course and i'm trying to write a program as a side project where the user inputs a multi-digit integer, and the program will break it apart into seperate integers, but im having trouble. Here is my code:
//program that will take the integer the user inputs and will output the digits added together.
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int n = get_int ("Please enter an integer:\n");
int d = 0;
{
while(n >= 0) //terminate loop when n reaches zero
d = n % 10; //takes the last number off and assigns it to digit variable
printf("%i\n", d); //should print the digit one after another
n = n / 10; //divides original number by 10
}
}
The output comes as "123" and then waits for another input. I know that i'm probably making a really dumb mistake but i can't figure out where i've gone wrong, help would be appreciated, PS this is my first post on here so sorry if i did not post the code the correct way