Console-supermarket payment system source code

Source: Internet
Author: User
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;
}
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.