I wrote this program in MATLAB that converts units (for homework). My teacher doesn't like MATLAB but I do, so I've decided to make everything a bit fancy and a bit overboard.

Thus far I've made my program to pop up a menu where in which you pick a unit then put in a value then it converts it to other units.

I want to know how to make it loop in itself so that if I want to convert more values, I can just go back so that I don't have to run the program again.

Can you help me please?

Ok I asked my other friend. It was much simpler than I thought it was.

function FtoC
exit=false;
while(exit~=true)
%This converts any temperature unit to any other.
entry=menu('Which unit do you want to convert?','Fahrenheit','Celsius','Kelvin','Exit');
switch(entry)
    case 1
      f=inputdlg('Enter Temperature in Fahrenheit','Fahrenheit to Celsius and Kelvin');
      f=str2num(mat2str(cell2mat(f)));
        if (f<-459.4)
            msgbox('Invalid temperature input, cannot exceed absolute zero','INVALID INPUT','error')
        else
            c=(5/9)*(f-32);
            k=c+273.15;
            msgbox([num2str(f),'°F',' = ',num2str(c),'°C',' = ',num2str(k),'°K'],'Temperature');  
        end    
    case 2
      c=inputdlg('Enter Temperature in Celsius','Celsius to Fahrenheit and Kelvin');
      c=str2num(mat2str(cell2mat(c)));
        if (c<-273.15)
            msgbox('Invalid temperature input, cannot exceed absolute zero','INVALID INPUT','error')
        else
            f=c*1.8+32;
            k=c+273.15;
            msgbox([num2str(c),'°C',' = ',num2str(f),'°F',' = ',num2str(k),'°K'],'Temperature');
        end    
    case 3
      k=inputdlg('Enter Temperature in Kelvin','Kelvin to Fahrenheit and Celsius');
      k=str2num(mat2str(cell2mat(k)));
        if k<0
           msgbox('Invalid temperature input, cannot exceed absolute zero','INVALID INPUT','error')
        else
            f=k*1.8-459.67;
            c=k-273.15;
            msgbox([num2str(k),'°K',' = ',num2str(f),'°F',' = ',num2str(c),'°C'],'Temperature');
        end
    otherwise
        exit=true;
        msgbox('Thank you for using this program!','Goodbye','help');  
end
end

Its a nice program, why don't you post it at kluid ( http://www.kluid.com ). You may like to make GUI out of this, a more professional approach. Nice work!

B4

I don't know what GUI is yet but I'll look into it.

There's really nothing hard about this program though. I learned it from my friend who's really good at programming and he likes to make things fancy and pretty.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.