Namespace Supermarket payment function
{
Class Program
{
Static Void Main ( String [] ARGs)
{
// 100 off for Members over yuan, off for non-members
Console. writeline ( " Welcome to [automatic payment for suguo supermarket] " );
Console. Write ( " Enter your sales amount: " );
String Jine = console. Readline (); // The string accepts the amount
Double Jine1 = convert. todouble (jine ); // Convert to double type
Console. Write ( " If you are a member of this store, enter (y/N ): " );
String VIP = console. Readline (); // Accept
Double Result; // Final payment amount
Result = pay (jine1, VIP ); // Define a function so that the final payment amount can call this function
If (Result> 0 )
{
Console. writeline ( " Amount Payable: {0} " , Result );
Console. writeline ( " Thank you! " );
}
If (Result < 0 )
{
Int Status = 3 ; // Define a status value. If you want to use the for statement to execute a maximum of three times, if you enter an error three times, the system will prompt "Use it later! "
For ( Int I = 0 ; I <= status; I ++)
{
Console. Write ( " The amount you entered is incorrect. Please enter it again: " );
Jine = console. Readline ();
Jine1 = convert. todouble (jine );
Console. Write ( " If you are a member of this store, enter (y/N ): " );
VIP = console. Readline ();
If (Jine1 < 0 )
{
Console. writeline ( " The amount you entered is incorrect! " );
Console. writeline (" You have {0} remaining opportunities. " , Status-I- 1 );
Continue ;
}
If (Jine1> = 0 )
{
Result = pay (jine1, VIP );
Console. writeline ( " Amount Payable: {0} " , Result );
Console. writeline ( " Thank you! " );
Break ;
}
}
}
}
// The following are functions:
Static Double Pay ( Double Money, String VIP)
{
Double Pay = 0 ; // Define an initial value: the initial amount is 0
If (VIP = " Y " | VIP = " Y " ) // Yes Member // If the member executes the following statement:
{
If (Money> = 100 )
{
Pay = money * 0.8 ;
Return Pay;
}
If (Money < 100 & Amp; Money & gt; = 0 )
{
Pay = money;
Return Pay;
}
If (Money < 0 ) // Prevent super exceptions
{
Pay = money;
Return Pay;
}
}
If (VIP = " N " | VIP = " N " ) // If you are not a member, execute the following statement:
{
If (Money> = 100 )
{
Pay = money * 0.9 ;
Return Pay;
}
If (Money < 100 & Amp; Money & gt; = 0 )
{
Pay = money;
Return Pay;
}
If (Money < 0 )
{
Pay = money;
Return Pay;
}
}
Return Pay;
}
}
}