Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  sumZero
Language: C/C++
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    srand( time( NULL ) );
    int sizeOfBoard;
    cout << "Podaj rozmiar talbicy: ";
    cin >> sizeOfBoard;
    int sumZero[sizeOfBoard];

    int sumOfBoardItems = 0;

    for(int i=0; i<sizeOfBoard; i++){
       // if(i!=sizeOfBoard-1){
            if(i==0&&(sumZero[i]==sumZero[i-1]))
                sumZero[i-1]=(rand() % 100) - 50;
            else{
                sumZero[i]=(rand() % 100) - 50;
                cout << sumZero[i] << endl;
            }
        //}
        sumOfBoardItems += sumZero[i];
        if(i==sizeOfBoard-1){
            sumZero[i] = 0 - sumOfBoardItems;
            cout << sumZero[i] << endl;
            sumOfBoardItems += sumZero[i];
        }
    }
    cout << "Wynik: " << sumOfBoardItems << endl;
    
    system("pause");

    return 0;
}
Comments: