Not sure not how to approach this

Hello Ladies and Gentlemen,

I am not sure how to proceed.

"Write a program that reads from the user a 5-digit whole number and produces a single integer value and prints it.
"Enter a number in 5 digits (type 0's if less than 5 digits): 00038

00038 = 38"

#include <iostream>
using namespace std;

int main ()
{
cout << "Please enter an integer value: ";
cin >> i;


return 0;
}

Should I be using c-string?
thanks


For a lazy and easy method, you can probably use c - string and convert each element one by one to an int and keep adding it to a temporary variable.

If you want a mathematical version, you can determine each digit in a single int by using the modulus operator -> % or keep dividing it using some recursive function but it is up to you how to figure that out :))))
Last edited on
Topic archived. No new replies allowed.