Question Locked

Adding individual integers in C

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am somewhat new to C++ (in the sense that I have a pretty good understanding of the concepts of programming, I am just unable to write a substantial program consisting of more than a handful of lines of code...) and am unsure of the best way to accomplish what I want. What I want is to write a program where the user enters an integer and the program adds the individual digits and displays the results. Ex: user enters 215, program adds 2+1+5, and displays the results. I am using Visual Studio 2008 Express, if it is relevant. Any and all suggestions or help would be greatly appreciated. Thanks in advance!

2 replies

by tony hopkinson

.net's string class will let you access it character by character, and teh Convert calls to strinr the char into a number so

So basically

int answer = 0;
for(index =0; index

This discussion is closed to new replies.