interactions statements

write a program that reads a positive least 2 digit and at most 6 digit integer and then checks if whether the last digit is a correct checksum which is the remainder in the division by 10 of the sum of the digits except for the last digit. the integer should be given by the user , do not accept values less than 10 or greater than 999999. for example correct numbers are:1236,886,9997,33; incorrect numbers are :2227,12,888,9999.
its easier if you read it as a string, instead of an integer.
remember that letter-'0' is the number, eg '9' - '0' is 9
note that % gives you the remainder eg sum%10 .. so 27%10 is 7

did you have a question beyond those hints?
Please solve it for me 🙏
its a 10-15 line problem for beginners. If I do this for you, you will never be able to do anything at all ... you will just get more and more behind. So I am going to do you a giant favor and not do this for you.
The description of the problem as a whole might sound formidable, but you just need to break it down into bite-sized pieces.

For example, just start with:
write a program that reads a positive least 2 digit and at most 6 digit integer

and
do not accept values less than 10 or greater than 999999.


You're just getting a number from the user.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std; // sue me
int main()
{
    cout << "Enter a number between 10 and 999999: ";
    int number;
    cin >> number;
    if (number < 10 || number > 999999)
    {
        cout << "value not accepted\n";
        return 1;
    }

    cout << "Value entered: " << number << '\n';

    return 0;
}


So then, the next part is
and then checks if whether the last digit is a correct checksum which is the remainder in the division by 10 of the sum of the digits except for the last digit

Even this may sound like a lot, but let's focus on the first part: "check .. the last digit".
How do you get the last digit of a number? do number % 10.

And then, you have
sum of the digits except for the last digit
.
How do you get the sum of the digits of a number? Just focus on this as your problem.
For example, just make a test program that prints the digits of a number:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

void print_digits(int number)
{
   // ...
}

int main()
{
    print_digits(1123);
}


Hint: number % 10 gets you the last digit of a number (1123 --> 3)
number / 10 divides the number by 10 to remove the last digit (1123 --> 112).
Last edited on
Topic archived. No new replies allowed.