Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagenone
function vector = countCoins(coinList)
vector = zeros(1, 4); %oppretter returvektoren
for i = 1:length(coinList)
    ifswitch coinList(i) ==
        case 1
        vector(1) = vector(1) + 1;
      elseif coinList(i) == case 5
        vector(2) = vector(2) + 1;
      elseif coinList(i) == case 10
        vector(3) = vector(3) + 1;
      elseif coinList(i) == case 20
        vector(4) = vector(4) + 1;
	else        otherwise
        error('Kun gyldige mynter!');
    end
end
end

...

Code Block
languagenone
function vector = countCoins(coinList)
vector = zeros(1, 4); % oppretter returvektoren
sum = 0;
for i = 1:length(coinList)
    ifswitch coinList(i) ==
        case 1
        vector(1) = vector(1) + 1;
    elseif coinList(i) ==    case 5
        vector(2) = vector(2) + 1;
      elseif coinList(i) == case 10
        vector(3) = vector(3) + 1;
     elseif  coinList(i) == case 20
        vector(4) = vector(4) + 1;
    else    otherwise
        error('Kun gyldige mynter!');
    end
    sum = sum + coinList(i);
    % dersom vi har talt et multiplum av 20 mynter, skriver vi ut summen
    if mod(i,20) == 0
        fprintf('Etter %d mynter har vi talt opp %d kroner', i, sum);
    end  
end
end

...