BTC USD 81,583.5 Gold USD 4,378.12
Time now: Jun 1, 12:00 AM

Help MATLAB prgraming...

budak ump ker? ak dlu kne jgak. tpi pakai c++.
nie ak tlong sket. yg ak punye projek dlu laa.
try laa run kt matlab.

#include<stdio.h>
#include<conio.h>

void main ()
{
int status, a, price, n;

printf("\t******************************************\n");
printf("\tWELCOME TO THE BEST OF THE BEST RESTAURANT\n");
printf("\t******************************************\n");

{
printf("Please choose your menu : ");
printf(" ______________________________________");
printf("| Number of unit | Price per unit (RM) |");
printf("|______________________________________|");
printf("| 1 through 4 | 10 |");
printf("| 5 and over | 9 |");
printf(" ______________________________________");


switch (status)
{
case 1 :

printf("-----------------------------------------------------");
printf("| Number of unit | Price per unit (RM) |");
printf("|-------------------------------------------------- |");
printf("| 1 through 4 | 10 |"<<endl;
printf("| 5 and over | 9 |"<<endl;
printf("-----------------------------------------------------");
printf("_____________________________________________________________________________");
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printf("-----------------------------------------------------------------------------");

printf("Please enter the amount of unit you wish to purchase : ");
for(a);

if ( a>=1 && a<=4 )

{
price = a * 10;

printf("Status : 1");
printf("Number of units ordered : ");
printf("Total price : RM");
}

else if ( a>=5 )

{
price = a * 9;

printf("Status : 1");
printf("Number of units ordered : ",a);
printf("Total price : RM",price);
}

else

{
printf("Status : 1");
printf("Number of units ordered : ",a);
printf("Invalid number of units.");
}

break;

case 2 :

printf("-----------------------------------------------------");
printf("| Number of unit | Price per unit (RM) |");
printf("|-------------------------------------------------- |");
printf("| 1 through 3 | 15 |");
printf("| 3 through 8 | 14 |");
printf("| 5 and over | 12 |");
printf("-----------------------------------------------------");
printf("_____________________________________________________________________________");
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printf("-----------------------------------------------------------------------------");

printf("Please enter the amount of unit you wish to purchase : ");
for(a);

if ( a>=1 && a<=3 )

{
price = a * 15;

printf("Status : 2");
printf("Number of units ordered : ");
printf("Total price : RM",price);
}

else if ( a>=4 && a<=8 )

{
price = a * 14;

printf("Status : 2");
printf("Number of units ordered : ",a);
printf("Total price : RM ",price);

}

else if ( a>=9 )

{
price = a * 12;

printf("Status : 2"<<endl;
printf("Number of units ordered : ",a);
printf("Total price : RM ",price);
}

else

{
printf("Status : 2");
printf("Number of units ordered : ");
printf("Invalid number of units.");
}

break;

default :

printf("Please enter the amount of unit you wish to purchase : ");
for(a);

if (a>=1)
{
printf("Status : ",status);
printf("Number of units orderes : ",a);
printf("Invalid status code.");
}

else
{
printf("Status : ",status);
printf("Number of units orderes : ",a);
printf("Invalid status code."<<endl;
printf("Invalid number of units.");
}

printf("Press: 1 to restart this porgram");
printf(" 2 to proceed with this program");
for(n);

if (n==1)
{
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<< endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
m++;
}

else if (n==2)
{
m = m - 1000;
}

return 0;
}
 
budak ump ker? ak dlu kne jgak. tpi pakai c++.
nie ak tlong sket. yg ak punye projek dlu laa.
try laa run kt matlab.

code yang diberi ini boleh compile?
 
yang ini code tanpa function dan tanpa error checking

Code:
clc;
clear all;
count = 1;
AmountDue = 0;
moredrink = 'Y';

while moredrink == 'Y'
    disp('1:    Hot Drink  RM1.00');
    disp('2:    Cold Drink RM1.00');
    disp('3:    Exit');
    reply = input('Please choose 1,2,3 :', 's');
    
    if reply == '1'
        AmountDue = AmountDue + 1;
        sugarreply = input('Do you want to add sugar? Y/N : ', 's');
        sugarreply = upper(sugarreply);
        if sugarreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
        milkreply = upper(input('Do you want to add milk? Y/N [Y]: ', 's'));
        if milkreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
    elseif reply == '2'
        AmountDue = AmountDue + 1;
        sugarreply = upper(input('Do you want to add sugar? Y/N : ', 's'));
        if sugarreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
        milkreply = input('Do you want to add milk? Y/N [Y]: ', 's');
        milkreply = upper(milkreply);
        if milkreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
    else
        break;
    end
    moredrink = upper(input('More Drink to order Y/N : ', 's'));
    if moredrink == 'Y'
        count = count + 1;
        if count > 3
            disp('You choose maximum order');
            moredrink = 'N';
        end
    end
end
fprintf('Total Price = %2.2f\n', AmountDue);
 
Last edited:
yang ini code tanpa function dan tanpa error checking

Code:
clc;
clear all;
count = 1;
AmountDue = 0;
moredrink = 'Y';

while moredrink == 'Y'
    disp('1:    Hot Drink  RM1.00');
    disp('2:    Cold Drink RM1.00');
    disp('3:    Exit');
    reply = input('Please choose 1,2,3 :', 's');
    
    if reply == '1'
        AmountDue = AmountDue + 1;
        sugarreply = input('Do you want to add sugar? Y/N : ', 's');
        sugarreply = upper(sugarreply);
        if sugarreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
        milkreply = upper(input('Do you want to add milk? Y/N [Y]: ', 's'));
        if milkreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
    elseif reply == '2'
        AmountDue = AmountDue + 1;
        sugarreply = upper(input('Do you want to add sugar? Y/N : ', 's'));
        if sugarreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
        milkreply = input('Do you want to add milk? Y/N [Y]: ', 's');
        milkreply = upper(milkreply);
        if milkreply == 'Y'
            AmountDue = AmountDue + 0.5;
        end
    else
        break;
    end
    moredrink = upper(input('More Drink to order Y/N : ', 's'));
    if moredrink == 'Y'
        count = count + 1;
        if count > 3
            disp('You choose maximum order');
            moredrink = 'N';
        end
    end
end
fprintf('Total Price = %2.2f\n', AmountDue);

owh...yg sblm ni ade error checking...
tp dh cuba tadi...
boleh2...
terima kasih banyak2...
thumb up 4 bro yunuskk..
nk tnye blaja mana???
 
Back
Top
Log in Register