Compiles fine just doing c in spare time. How do you get this program to compile
ID: 3683858 • Letter: C
Question
Compiles fine just doing c in spare time. How do you get this program to compile with an "for" loop instead of while?
#include #include using namespace std;
int addUp(char*, int);
int main()
{ const int NUMBERS = 20; int mydigits[NUMBERS]; char* num=new char; int tot = 0; int number; int finalTot = 0;
cout << "Enter number ";
cin.getline(num, NUMBERS);
number = atoi(num);
int i = number % 10;
int add = number % 10; //Logic for getting sum of digits while (number > 0)
{ i = number % 10;
tot = tot + i;
number = number / 10; }
cout << tot << endl; cout << add << endl;
system("PAUSE");
return 0; }
//Ignore unrelated stuff
Explanation / Answer
put this code insted of while block
for(i = number % 10;number>0;number/=10)
{
tot = tot + i;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.