Versions Compared

Key

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

 a) 

 

Code Block
languagetext
function advice = getAdvice(age)
if age < 0
    error('Ugyldig input!');
end
if age <= 30
    advice = 'Aksjer';
elseif age <= 50
    advice = 'Fond';
else
    advice = 'Konto';
end
end

 

 

b) 

 

Code Block
languagetext
function expectedReturn(amount, investType)
money = amount;
if strcmp(investType, 'Aksjer')
    money = amount * 1.20;
elseif strcmp(investType, 'Fond')
    money = amount * 1.10;
elseif strcmp(investType, 'Konto')
    money = amount * 1.05;
end
fprintf('Du kan forvente å ha %i kroner etter ett år hvis du investerer i %s\n', money, investType);
end

 

 

c)

 

Code Block
languagetext
function expectedReturn(amount, investType)
money = amount;
risk = 0;
if strcmp(investType, 'Aksjer')
    money = amount * 1.20;
    risk = 10;
elseif strcmp(investType, 'Fond')
    money = amount * 1.10;
    risk = 5;
elseif strcmp(investType, 'Konto')
    money = amount * 1.05;
end
fprintf('Du kan forvente å ha %i kroner etter ett Ã¥r hvis du investerer i %s\nSjansen for å tape pengene dine er %i prosent\n', money, investType, risk);
end

 

 

d)

 

Code Block
languagetext
function advisor()
age = input('Hvor gammel er du? ');
amount = input('Hvor mye vil du investere? ');
investType = getAdvice(age);
fprintf('Jeg anbefaler deg å investere i %s\n', investType);
expectedReturn(amount, investType);
end