printing multiple variables outside of a function
이전 댓글 표시
This is the prompt i am given:
1. The cost of sending a package by an express delivery service is $15 for the first two pounds, and $4.25 for each pound over two pounds. Write a program that computes the cost of mailing the packages. Your program must use a function to calculate the cost. Use the test data: 1.5 16 103 lbs The data should be read by the main program from a text file. The data is passed to the function. The results and any other output should be printed by the main program.
The issue i have is printing outside of the function, and in the main program. Heres what i have so far:
Main program:
clc
clear
disp(' name')
disp(' Project 8 problem 1')
ffrd1=fopen('data81.txt','rt');
wei=fscanf(ffrd1,'%f',3);
fclose(ffrd1);
co=cost(wei);
fprintf('%5f',co);
Function:
function [x,y,z]=cost(a)
if a<= 2
x=15;
elseif a<= 100
y=15+4.25*(a-2);
else
z=5; (this was just a test number until i got it working)
end
Any help would be greatly appreciated.
댓글 수: 3
Bryan Morrow
2014년 5월 4일
Jan
2014년 5월 4일
Please format your code properly. Use the "{} Code" button.
Do not forget to explain, which problems the shown code has. The less the readers have to guess, the more likely is a useful answer.
Bryan Morrow
2014년 5월 4일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!