Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote