Computing using Arrays

Hi guys,

I wish to know, how I can use each of the digits of a 15 digit code supplied by a user to compute a formula like this:
Given that the 15 digit code is represented as ABCDEFGHIJKLMNO
A*3+B*7+C*3+D*3+E*7F*3+G*3+H*7+I*3+J*3+K*7+L*3+M*3+N*7+O*3

How do i find the result of this computation using an array to represent the 15 digit code in which user will input sigle digits from A to O.
Where are the 3s and 7s coming from? That's what the user enters? If so, then what exactly is the computation involved in the letters?

Edit: And yes, please delete your other duplicate posts, as dutch says below. I didn't notice until now.
Last edited on
@CollinsLainzo, please delete your duplicate posts. Just keep this one.

@Ganado, I think the letters just represent the single decimal digits of a 15 digit number. The 3's and 7's are part of the formula. So if the number was 123456789012345 the calculation would be 1*3 + 2*7 + 3*3 + ...
Last edited on
Sorry the letters actually represent a 15 digit code which will be supplied by the user at tun time. Once the user inputs the 15 digit code, each number of the code should represent the corresponding alphabet (A, B, C etc) and computation should take place to determine the final value. the 3s and 7s are constants to be use for multiplication of the digits of the code
@Dutch, Thanks for providing clarity. Exactly what i am trying to explain. Can I get a solution which with little complexity but good effficiency.

NB: Duplicate deleted. Thanks!
You should delete the duplicate in the beginner's forum, too.

Do you know how to index an array?

1
2
3
4
5
char s[100];
std::getline(s, sizeof s);

// s[0] is the first element
// s[1] is the second... 

Can I get a solution which with little complexity but good effficiency.

the idea / pseudocode

int table[] = {3,7}; //used an array. but professors get irritated when you do stuff logically...
for(x=...)
{
cin >> input;
result += input*table[x%3==0] //adjust this for your pattern or adjust x in loop
}

note its a pattern of 3,3,7 repeating, and you happen to start at an offset.
Last edited on
Topic archived. No new replies allowed.