+ 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.

1st Nov 2018, 1:38 AM
PrinceCEE
PrinceCEE - avatar
6 Respuestas
+ 7
What have you tried? Can you show your attempt?
1st Nov 2018, 2:00 AM
jay
jay - avatar
+ 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++
1st Nov 2018, 2:33 AM
jay
jay - avatar
+ 6
Without braces {} it is not. There is a c compiler on SoloLearn. https://code.sololearn.com/ckspAOUrNzYi/?ref=app
2nd Nov 2018, 10:53 AM
jay
jay - avatar
+ 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; }
1st Nov 2018, 2:10 AM
PrinceCEE
PrinceCEE - avatar
0
It's actually C, but there's no c in sololearn. I tried it on C++, still gave the same output
2nd Nov 2018, 8:46 AM
PrinceCEE
PrinceCEE - avatar
0
I'll try it again today. The scoping is correct
2nd Nov 2018, 8:48 AM
PrinceCEE
PrinceCEE - avatar