Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Discount Assignment: If/Else Statement

Guest
Oct 19, 2013 Oct 19, 2013

Its an assignment that I've spent hours on:

http://imageshack.us/a/img834/7124/273e.png

http://imageshack.us/a/img706/4691/fhfd.png

That's how far I've gotten so far, next up is my code:

__________________________________________________________________________________________________________________________

var body_txt:TextField = new TextField();

body_txt.x = 225;

body_txt.y = 300;

body_txt.autoSize = TextFieldAutoSize.LEFT;

var myFormat:TextFormat= new TextFormat();

var yourPurchase:String;

var yourDiscount:String;

var yourPrice:String;

var discount:Number;

var total:Number;

yourPurchase = max_txt.text;

discount: 10.00 / 10%

yourDiscount = discount_txt.text;

yourPrice = price_txt.text;

total = yourPurchase - discount

if(yourDiscount)

{

      trace();

}

else

{

     trace();

}

__________________________________________________________________________________________________________________________

As you can see, I have no clue on how to get the discount written in code, I don't know how.

Please explain as best as you can about how to solve this dilemma (in Laymen's Terms if possible). Thank you!

TOPICS
ActionScript
885
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 20, 2013 Oct 20, 2013

use:

______________________________________________________________________ ____________________________________________________

var body_txt:TextField = new TextField();

body_txt.x = 225;

body_txt.y = 300;

body_txt.autoSize = TextFieldAutoSize.LEFT;

var myFormat:TextFormat= new TextFormat();

// i'm not sure what the above is

var yourPurchase:Number;

var yourDiscount:Number;

var discount:Number=.1;

// the code below (up to formatF) needs to execute AFTER the user completes entry into max_txt

yourPurchase =

...
Translate
Community Expert ,
Oct 20, 2013 Oct 20, 2013

use:

______________________________________________________________________ ____________________________________________________

var body_txt:TextField = new TextField();

body_txt.x = 225;

body_txt.y = 300;

body_txt.autoSize = TextFieldAutoSize.LEFT;

var myFormat:TextFormat= new TextFormat();

// i'm not sure what the above is

var yourPurchase:Number;

var yourDiscount:Number;

var discount:Number=.1;

// the code below (up to formatF) needs to execute AFTER the user completes entry into max_txt

yourPurchase = Number(max_txt.text);

if(yourPurchase>10){
yourDiscount=discount*yourPurchase;
} else {
yourDiscount=0;
}

discount_txt.text=formatF(yourDiscount);

price_txt.text = formatF(yourPurchase*(1-discount));

function formatF(n:Number):String{

// now write a function that converts numbers to dollars and cents for display

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 20, 2013 Oct 20, 2013

// now write a function that converts numbers to dollars and cents for display

Thank you greatly for the help, I appreciate it and am almost finished this assignment. One last question: I tried to convert numbers to dollars but I am not sure how. I am still a beginner with programming, but I am slowly getting better. May I ask you how I should convert it? I've looked on Google for help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2013 Oct 21, 2013

:

function formatF(n:Number):String{

    var s:String = String(Math.round(100*n)/100);

    if(s.indexOf(".")==-1){

        return "$"+s+".00";

    } else {

        while(s.indexOf(".")>=s.length-2){

            s=s+"0";

        }

    }

    return "$"+s

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 21, 2013 Oct 21, 2013
LATEST

Is it ethical to just hand someone the code for a homework assignment?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines