程序在 a[ch] 和 b[nech] 上向我发送 -858993460 值,为什么?我无法理解...如果我使用cout<<m[i]
它代替cout<<a[ch]<<endl;
它工作正常...向我显示偶数和赔率但是当我尝试将它们发送到另一个数组时值出错(我需要另外两个数组 a[ch]和 b[nech])
#include <iostream>
#include <conio.h>
#include <string>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
int main()
{
int i,n;
int m[3], a[3]={0}, b[3]={0};
int ch=0, nech=0;
for(i=0; i<3; ++i)
{
cout<<i+1<<". Studenski fark. nomer: ";
do
{
cin>>m[i];
}
while(!(m[i]>=1e7 && m[i]<1e8));
if(m[i]%2==0)
{
m[i]==a[ch]; ch++;
//cout<<m[i]<<endl; "without the down 'fors' it works"
}
else
{
m[i]==b[nech]; nech++;
//cout<<m[i]<<endl; "without the down 'fors' it works"
}
}
cout<<"\nVsichki fakultetni nomera: "<<endl;
for(i=0; i<3; ++i)
cout<<m[i]<<"\t";
cout<<"Chetni fark nomera: \n";
if(ch!=0)
for(i=0;i<ch;i++)
cout<<a[ch]<<"\t"; //"with {0} on 'a' I receive 0 as result"
else
cout<<"nqma chetni fak nomera";
if(nech!=0)
for(i=0;i<nech;i++)
cout<<b[nech]<<"\t"; //"same here 0 as result with {b}"
else
cout<<"Nqma nechetni fak nomera";
getch();
}