+ 1
I need answer to this C++ question
If a number is input through the keyboard, write a program that prints a new number by adding 1 to each of its digits.
6 Respuestas
+ 7
What have you tried? Can you show your attempt?
+ 6
Check that your while loop has the correct scoping. Currently it is only ever repeating one line.
Also, you are not adding 1 anywhere. Perhaps you could here:
numArray[i] = (thenum % 10) + 1;
Also, this looks more like c, not c++
+ 6
Without braces {} it is not. There is a c compiler on SoloLearn.
https://code.sololearn.com/ckspAOUrNzYi/?ref=app
+ 3
int main()
{
int thenum;
printf ("\nEnter the five digit number: ");
scanf("%d", &thenum);
int numArray[5];
int i = 4;
while (i <= 0)
numArray[i] = (thenum % 10);
printf("\n%d", numArray[i]);
thenum = thenum / 10;
printf("\n%d", thenum);
i--;
return 0;
}
0
It's actually C, but there's no c in sololearn. I tried it on C++, still gave the same output
0
I'll try it again today. The scoping is correct