In a question i am required to add every other number starting from the right most side and going left on every other number. I have a code that is almost right as i am led to beleive. the code is:
#include <iostream>
#include <cmath>
int main ()
{
int i, cardNumber, checkSum = 0;
// Compute checksum of every other digit starting from right-most digit
for (i = cardNumber.Length - 1; i >= 0; i -= 2)
{
checkSum += (cardNumber[i] - 1);
cout << checksum << endl;
}
// Now take digits not included in first checksum, multiple by two,
// and compute checksum of resulting digits
for (i = cardNumber.Length - 2; i >= 0; i -= 2)
{
int val = ((cardNumber[i] - 1) * 2);
while (val > 0)
{
checkSum += (val % 10);
val /= 10;
}
cout << val << endl;
}
// Number is valid if sum of both checksums MOD 10 equals 0
if ((checkSum % 10) == 0)
{
cout << "Error not vailid";
}
return 0;
}
the feed back that i recieve is:
1>------ Build started: Project: idontknow, Configuration: Debug Win32 ------
1>Compiling...
1>ddd.cpp
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(13) : error C2228: left of '.Length' must have class/struct/union
1> type is 'int'
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(15) : error C2109: subscript requires array or pointer type
1>d:\my documents\visual studio 2008
\projects\idontknow\idontknow\ddd.cpp(18) : error C2065: 'cout' : undeclared identifier
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(18) : error C2065: 'checksum' : undeclared identifier
1>d:\my documents\visual studio 2008
\projects\idontknow\idontknow\ddd.cpp(18) : error C2065: 'endl' : undeclared identifier
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(22) : error C2228: left of '.Length' must have class/struct/union
1> type is 'int'
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(24) : error C2109: subscript requires array or pointer type
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(31) : error C2065: 'cout' : undeclared identifier
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(31) : error C2065: 'endl' : undeclared identifier
1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(38) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://d:\My Documents\Visual Studio 2008\Projects\idontknow\idontknow\Debug\BuildLog.htm"
1>idontknow - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========