printing multiple variables outside of a function
Afficher commentaires plus anciens
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 commentaires
Bryan Morrow
le 4 Mai 2014
Jan
le 4 Mai 2014
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
le 4 Mai 2014
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!