Witam, zmagam się z problemem związanym z tematem.
Otóż program ma na wejściu X peseli, pierwsza linijka to ilość, następne to właśnie pesele. Trzeba sprawdzić czy jest on poprawny, więc
Pierwszą cyfrę mnożymy przez 1,
drugą cyfrę mnożymy przez 3,
trzecią cyfrę mnożymy przez 7,
czwarta cyfrę mnożymy przez 9,
piątą cyfrę mnożymy przez 1,
szóstą cyfrę mnożymy przez 3,
siódmą cyfrę mnożymy przez 7,
ósmą cyfrę mnożymy przez 9,
dziewiątą cyfrę mnożymy przez 1,
dziesiątą cyfrę mnożymy przez 3,
jedenastą cyfrę mnożymy przez 1.
Następnie uzyskane wyniki do siebie dodajemy, jeśli ostatnia cyfra wyniku jest równa 0 to pesel jest poprawny.
Co w tym kodzie jest źle, co powinienem poprawić i jak?
To mój kod, który niestety nie działa.
#include <iostream>
using namespace std;
int cyfry[ 10 ];
int cyfrixy[ 10 ];
int main() {
int a;
int pesel;
cin >> a >> pesel;
int( pesel % 10 ) = * cyfry;
int(( pesel / 10 ) % 10 ) = *( cyfry + 1 );
int(( pesel / 100 ) % 10 ) = *( cyfry + 2 );
int(( pesel / 1000 ) % 10 ) = *( cyfry + 3 );
int(( pesel / 10000 ) % 10 ) = *( cyfry + 4 );
int(( pesel / 100000 ) % 10 ) = *( cyfry + 5 );
int(( pesel / 1000000 ) % 10 ) = *( cyfry + 6 );
int(( pesel / 10000000 ) % 10 ) = *( cyfry + 7 );
int(( pesel / 100000000 ) % 10 ) = *( cyfry + 8 );
int(( pesel / 1000000000 ) % 10 ) = *( cyfry + 9 );
int(( pesel / 10000000000 ) % 10 ) = *( cyfry + 10 );
for( int i = 0; i < a; i++ ) {
cin >> pesel;
}
int * cyfrixy = * cyfry * 1;
int *( cyfrixy + 1 ) = *( cyfry + 1 ) * 3;
int *( cyfrixy + 2 ) = *( cyfry + 2 ) * 7;
int *( cyfrixy + 3 ) = *( cyfry + 3 ) * 9;
int *( cyfrixy + 4 ) = *( cyfry + 4 ) * 1;
int *( cyfrixy + 5 ) = *( cyfry + 5 ) * 3;
int *( cyfrixy + 6 ) = *( cyfry + 6 ) * 7;
int *( cyfrixy + 7 ) = *( cyfry + 7 ) * 9;
int *( cyfrixy + 8 ) = *( cyfry + 8 ) * 1;
int *( cyfrixy + 9 ) = *( cyfry + 9 ) * 3;
int *( cyfrixy + 10 ) = *( cyfry + 10 ) * 1;
int suma = * cyfrixy + *( cyfrixy + 1 ) + *( cyfrixy + 2 ) + *( cyfrixy + 3 ) + *( cyfrixy + 4 ) + *( cyfrixy + 5 ) + *( cyfrixy + 6 ) + *( cyfrixy + 7 ) + *( cyfrixy + 8 ) + *( cyfrixy + 9 ) + *( cyfrixy + 10 );
for( int i = 0; i < a; i++ ) {
if(( suma % 10 ) == 0 )
cout << *( cyfrixy + 1 ) << endl;
else
cout << *( cyfrixy + 5 ) << endl;
}
return 0;
}
A tu log
prog.cpp: In function 'int main()':
prog.cpp:11:19: error: lvalue required as left operand of assignment
int (pesel % 10) = *cyfry;
^
prog.cpp:12:24: error: lvalue required as left operand of assignment
int ((pesel/10) % 10) = *(cyfry+1);
^
prog.cpp:13:25: error: lvalue required as left operand of assignment
int ((pesel/100) % 10) = *(cyfry+2);
^
prog.cpp:14:26: error: lvalue required as left operand of assignment
int ((pesel/1000) % 10) = *(cyfry+3);
^
prog.cpp:15:27: error: lvalue required as left operand of assignment
int ((pesel/10000) % 10) = *(cyfry+4);
^
prog.cpp:16:28: error: lvalue required as left operand of assignment
int ((pesel/100000) % 10) = *(cyfry+5);
^
prog.cpp:17:29: error: lvalue required as left operand of assignment
int ((pesel/1000000) % 10) = *(cyfry+6);
^
prog.cpp:18:30: error: lvalue required as left operand of assignment
int ((pesel/10000000) % 10) = *(cyfry+7);
^
prog.cpp:19:31: error: lvalue required as left operand of assignment
int ((pesel/100000000) % 10) = *(cyfry+8);
^
prog.cpp:20:32: error: lvalue required as left operand of assignment
int ((pesel/1000000000) % 10) = *(cyfry+9);
^
prog.cpp:21:33: error: lvalue required as left operand of assignment
int ((pesel/10000000000) % 10) = *(cyfry+10);
^
prog.cpp:25:26: error: invalid conversion from 'int' to 'int*' [-fpermissive]
int *cyfrixy = *cyfry * 1;
^
prog.cpp:26:15: error: expected ')' before '+' token
int *(cyfrixy+1) = *(cyfry+1) * 3;
^
prog.cpp:26:15: error: expected initializer before '+' token
prog.cpp:27:15: error: expected ')' before '+' token
int *(cyfrixy+2) = *(cyfry+2) * 7;
^
prog.cpp:27:15: error: expected initializer before '+' token
prog.cpp:28:15: error: expected ')' before '+' token
int *(cyfrixy+3) = *(cyfry+3) * 9;
^
prog.cpp:28:15: error: expected initializer before '+' token
prog.cpp:29:15: error: expected ')' before '+' token
int *(cyfrixy+4) = *(cyfry+4) * 1;
^
prog.cpp:29:15: error: expected initializer before '+' token
prog.cpp:30:15: error: expected ')' before '+' token
int *(cyfrixy+5) = *(cyfry+5) * 3;
^
prog.cpp:30:15: error: expected initializer before '+' token
prog.cpp:31:15: error: expected ')' before '+' token
int *(cyfrixy+6) = *(cyfry+6) * 7;
^
prog.cpp:31:15: error: expected initializer before '+' token
prog.cpp:32:15: error: expected ')' before '+' token
int *(cyfrixy+7) = *(cyfry+7) * 9;
^
prog.cpp:32:15: error: expected initializer before '+' token
prog.cpp:33:15: error: expected ')' before '+' token
int *(cyfrixy+8) = *(cyfry+8) * 1;
^
prog.cpp:33:15: error: expected initializer before '+' token
prog.cpp:34:15: error: expected ')' before '+' token
int *(cyfrixy+9) = *(cyfry+9) * 3;
^
prog.cpp:34:15: error: expected initializer before '+' token
prog.cpp:35:15: error: expected ')' before '+' token
int *(cyfrixy+10) = *(cyfry+10) * 1;
^
prog.cpp:35:15: error: expected initializer before '+' token
prog.cpp:41:12: error: 'D' was not declared in this scope
cout << D << endl;
^
prog.cpp:43:12: error: 'N' was not declared in this scope
cout << N << endl;
^
Z góry dziękuję za pomoc.