Question

In: Computer Science

I'm writing a program that requires that I use the check sum technique with a for...

I'm writing a program that requires that I use the check sum technique with a for loop. A student enters their seven digit ID number. The seventh digit is determined from the other digits by this formula:

7th digit = (1 *(1st digit) + 2 * (2nd digit) + ... + 6 * (6th digit)) %10.

The program should prompt users to enter a 7-digit number, and print valid if the actual 7th digit matches the computed 7th digit. Basicaly, an ID of 1234567 is invalid but 1234561 IS valid because the first and seventh digit are equal.

I can do this with a while loop but I must use a for loop.

Solutions

Expert Solution

Hi,I wrote the code in C using for-loop.Hope,it will help you.Any other further doubts.Please feel free to ask if any other further doubts.We love to help you

  1. #include <iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4. int main() {
  5.    int num;
  6.    printf("Enter an ID \n"); //asks for ID from user
  7. scanf("%d",&num); //
  8.    int check=0;
  9.    for(int i=1;i<=7;i++)
  10.    {
  11.    int digit=num%10; //gets each digit
  12.    if(i != 7)
  13.    {
  14.    check+=i*digit; //calculates the 7th digit
  15.    }
  16.    else
  17.    {
  18.    check=check%10; //7th digit calculated
  19.    if(digit==check) //validation
  20.    {
  21.    printf("VALID ID \n");
  22.    }
  23.    else
  24.    {
  25.    printf("INVALID ID \n");
  26.    }
  27.    }
  28.    num=num/10;
  29.    }
  30.    return 0;
  31. }

Related Solutions

Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
what is a good hypothesis/prediction I can use for a scientific essay I'm writing for penicillin...
what is a good hypothesis/prediction I can use for a scientific essay I'm writing for penicillin (antibiotic) can you give me ideas? and can you please describe the source of the compound in your own words please don't copy and paste something you find online and can you write neatly
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
I'm writing a program using EasyReader class. The program wil give me the how much money...
I'm writing a program using EasyReader class. The program wil give me the how much money is left. e.g. someone paid 50 pounds for their 20 pounds worth of groceries so the output will be 30 pounds. my question is, I want it to print out how the change should be made up. how many 10 pounds, 5 pounds, 2 pound and so on, is in the change. how should I write the program
1a) If I'm writing a program which involves many insertion and deletion operations, and memory is...
1a) If I'm writing a program which involves many insertion and deletion operations, and memory is not a concern, which of the following should I choose to hold my data? A: linked list B: fixed-size array C: dynamic array D: any of the above 1b) What about if I'm writing a program and I want the program to be flexible on the data with various sizes, and the program also needs to provide fast access to the data? Which of...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
I had a question about ethnicity. I'm writing a paper and am a bit confused on...
I had a question about ethnicity. I'm writing a paper and am a bit confused on the word ethnicity. For example if a person is half asian and half white with some european ancestry what would you consider their ethnicity to be? And how does that differ from race?
Hi... I have a proposal to do and I'm writing about ( Hospital management system )...
Hi... I have a proposal to do and I'm writing about ( Hospital management system ) so I have a part about ( Motivation for the research) I need someone to write it.
I wrote this program to check a string is palindrome or not. but in both cases,...
I wrote this program to check a string is palindrome or not. but in both cases, it gives me palindrome. could someone help me with this program? it has an error I couldn't find. when I run the code and give a string, in both cases it gives me palindrome. for example if I give Pop it says it is a palindrome but if I give Salima, it also says palindrome. #include<string> #include <iostream> using namespace std; class PString:public string...
Using an induction proof technique, prove that the sum from i=1 to n of (2i-1) equals...
Using an induction proof technique, prove that the sum from i=1 to n of (2i-1) equals n*n
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT