Stránka 1 z 1

C++ pole

Napsal: stř 26. pro 2012, 12:12
od acerr
Proč to píše : too many initializers for 'char [1000]' ? kde je chyba?

Kód: Vybrat vše

#include <iostream>
using namespace std;
int main()
{
    char jmeno[1000]= {"sasa","petr", "jan", "mikes", "ales", "petra", "nina", "jana", "pavel", "romana"};
    int  suma[10]= {1,2,3,4,14,16,18,20,19,30};
    char jmeno_min_deset[1000];
    int suma_min_deset [10];

    for (int i = 0; i<10;i++)
    {
        if (suma[i]<10)
        {
            int a = 0;
            suma_min_deset[a] = suma[i] ;
            jmeno_min_deset[a] = jmeno[i];
            a++;
        }
        else
            cout << jmeno[i] << " prispel: " << suma[i];
    }

    return 0;
}

Re: C++ pole

Napsal: stř 26. pro 2012, 18:21
od OndraSter

Re: C++ pole

Napsal: stř 26. pro 2012, 19:55
od acerr
teď už to běhá, jen to nic z pole kde by mělo být několik lidí s menším příspěvkem než 10 nezobrazuje, proč?

Kód: Vybrat vše

#include <iostream>
using namespace std;
int main()
{
    char *jmeno[10] = {"sasa","petr", "jan", "mikes", "ales", "petra", "nina", "jana", "pavel", "romana"};
    int  suma[10]= {1,2,3,4,14,16,18,20,19,30};
    char *jmeno_min_deset[10];
    int suma_min_deset [10];
     cout << "prispevky vetsi nez 10:\n";

    for (int i = 0; i<10;i++)
    {
        if (suma[i]<10)
        {
            int a = 0;
            suma_min_deset[a] = suma[i] ;
            jmeno_min_deset[a] = jmeno[i];
            a++;
        }
        else
           cout << jmeno[i] << " prispel: " << suma[i] << endl;
    }

    cout << "\n\n\nPrispevky mensi nez 10: ";
    for (int n = 0;n>10;n++)
    {
        cout << jmeno_min_deset[n] << " prispel: " << suma_min_deset[n] << endl;
    }

    return 0;
}

Re: C++ pole

Napsal: stř 26. pro 2012, 20:49
od N_o_c_l_a_f
Protoze to tam mas v podmince neasi...

Re: C++ pole

Napsal: stř 26. pro 2012, 21:12
od acerr
v podmínce je že pokud suma je menší než 10 tak ta suma a jmeno jsou přiřazeny tomu druhému poly - či kde je chyba? podtím je přeci cyklus co vypisuje to druhé pole

Re: C++ pole

Napsal: stř 26. pro 2012, 21:14
od Exp

Kód: Vybrat vše

for (int n = 0;n>10;n++)
Obrácenej operátor...

Re: C++ pole

Napsal: stř 26. pro 2012, 21:25
od acerr
díky, věděl sem, že to bude nějaká kravina co mám špatně

Re: C++ pole

Napsal: stř 26. pro 2012, 21:38
od acerr
A teď je to teda co (už mi došla fantazie)

Obrázek

Kód: Vybrat vše

#include <iostream>
using namespace std;
int main()
{
    char *jmeno[10] = {"sasa","petr", "jan", "mikes", "ales", "petra", "nina", "jana", "pavel", "romana"};
    int  suma[10]= {1,2,3,4,14,16,18,20,19,30};
    char *jmeno_min_deset[10];
    int suma_min_deset [10];
     cout << "prispevky vetsi nez 10:\n";

    for (int i = 0; i<10;i++)
    {
        if (suma[i]<10)
        {
            int a = 0;
            suma_min_deset[a] = suma[i] ;
            jmeno_min_deset[a] = jmeno[i];
            a++;
        }
        else
           cout << jmeno[i] << " prispel: " << suma[i] << endl;
    }

    cout << "\n\n\nPrispevky mensi nez 10: ";

    for (int n = 0; n < 3;n++)
    {
        cout << jmeno_min_deset[n] << suma_min_deset[n] << endl;
    }
    return 0;
}

Re: C++ pole

Napsal: stř 26. pro 2012, 21:42
od Exp

Kód: Vybrat vše

if (suma[i]<10)
        {
            int a = 0;
            suma_min_deset[a] = suma[i] ;
            jmeno_min_deset[a] = jmeno[i];
            a++;
        }
a je vždycky nula. Inicializaci dej před cyklus.

Re: C++ pole

Napsal: stř 26. pro 2012, 21:43
od acerr
ok, díky