C++ help ?

buzzard34

Gawd
Joined
Feb 14, 2004
Messages
619
Hi, I had an earlier post but it got f*ckd over by database issues so I am reposting this. I need to find a way to tie in an ID check digit of some sort. Here's my code so far:
#include <iostream>
using namespace std;

int main()
{
int a, b, c, d, sum;


cout << "Enter the first 2 digits of your 8-digit ID number now.\n";
cin >> a;

cout << "Now the next 2 digits?\n";
cin >> b;

cout << "And the next 2?\n";
cin >> c;

cout << "Finally the last 2 digits. Thank You!\n";
cin >> d;

sum = a+b+c+d;
sum%26

cout << "Your ID number with appended checkdigits: \n";

return 0;
}

Ok so there is my coed, now I just need to figure out a rule that goes like this example:
ID=34567890
SUM=34+56+78+90
sum%26=24
24->Y
34567890Y <-IDnumber with checkdigit.

I AM NOT LOOKING FOR ANSWERS, just suggestions/help. Thanks!

 
You'd need to store the result of sum%26 into a variable...lets call it 'temp'
Associate the value in 'temp' with the correct letter of the alphabet.
Print contents of variable a, b, c, d, and temp all on the same line.

What would you like to do with the results? Do you just need to print it to stdout? or do you
need to store the result for later refrence?
 
a_n_d_y15 said:
You'd need to store the result of sum%26 into a variable...lets call it 'temp'
Associate the value in 'temp' with the correct letter of the alphabet.
Print contents of variable a, b, c, d, and temp all on the same line.
Ok so something like this?
.
.
sum%26 = temp

cout << whatever
cout <<temp<<endl;
return 0;

did i mention i somehow need to make a rule assigning an uppercase letter to the ID number as the checkdigit? (kinda like the example)
 
buzzard34 said:
Ok so something like this?
.
.
sum%26 = temp

cout << whatever
cout <<temp<<endl;
return 0;

did i mention i somehow need to make a rule assigning an uppercase letter to the ID number as the checkdigit? (kinda like the example)

close, but you would need to declare the variable and store the result into the variable;


int temp;
temp = sum%26;

// associate temp with a letter
// i'm not sure the most effecient way...i'm sure someone else has a better apporach,
// initialize an array with every letter from the alphabet
// ( element 0 = 'A', element 1 = 'B'... and so on ), and then use the value in temp
// to access that array element. That array element = the letter that will be put at the
// end of the id.


cout << a << b << c << d << temp;


something like that...haven't done C++ lately
 
Ok thanks that helps but I did something a little different which I hope works as well.
 
Back
Top