locked
exercise RRS feed

  • Question

  • I have a problem with an exercise.

    Until here it works just fine

    private

     

    : System::Void btnrezultat_Click(System::Object^ sender, System::EventArgs^ e) {

    lblRzultat->Visible=

    true;

     

    double x, y;

     

    double i;

    x=Single::Parse(txtX->Text);

    y=Single::Parse(txtY->Text);

     

    do {

     

    if(x<=0 || y<=0 || x>y)

    lblRzultat->Text= String::Format(

    "Trebuie ca 0 < X <= Y");

    }

    I work in visual c++ form application.

    When I put the rest of the code:

     

    while (x<=0 || y<=0 || x>y);

     

    for (i = x; i<y; i++)

     

    switch(tip_numar(i)) {

     

    case DEFICIENT:

    lblRzultat->Text= String::Format(

    "Este deficient", i.ToString());

     

    case PERFECT:

    lblRzultat->Text= String::Format(

    "Este perfect ", i.ToString());

     

    case ABUNDENT:

    lblRzultat->Text= String::Format(

    "Este abundent ", i.ToString());

    }

    It blocks while executing.

    And here are the definitions:

    int

     

    suma_divizori(int n) {

     

    int i, s=1;

     

    for(i=2; i<= n/2; i++)

     

    if (n%i == 0) s+=i;

     

    return s;

    }

     

    // function that returns the type of the number(DEFICIENT , PERFECT , ABUNDENT)

     

    int tip_numar( int n) {

     

    double s = suma_divizori(n);

     

    if(s<n) return DEFICIENT;

     

    if(s>n) return ABUNDENT;

     

    return PERFECT;

    }

    Thank you

     

    Tuesday, January 11, 2011 3:29 PM

Answers

  • I haven't succeded to solev it. I moved to another one.

    Thank you anyway.

    • Marked as answer by Eduard77 Monday, January 17, 2011 1:51 PM
    Monday, January 17, 2011 1:51 PM

All replies

  • do {

    if (x<=0 || y<=0 || x>y)

    lblRzultat->Text= String::Format(

    "Trebuie ca 0 < X <= Y" );

    }while (x<=0 || y<=0 || x>y);

     

    It does not need a cycle!

    Correctly as follows:

    if (x<=0 || y<=0 || x>y) {

    lblRzultat->Text= String::Format( "Trebuie ca 0 < X <= Y" );

    return;

    }

    • Proposed as answer by Curica Monday, January 17, 2011 5:15 PM
    Tuesday, January 11, 2011 4:41 PM
  •  

    Hi,

     

    I'm very interested in hearing more about your issue, did you solve your problem?

    If so please share the solution with us and mark the right answers.

    If not please let me know and I will tray to help you find further solutions.

     

    Have a nice day!

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 17, 2011 7:14 AM
  • I haven't succeded to solev it. I moved to another one.

    Thank you anyway.

    • Marked as answer by Eduard77 Monday, January 17, 2011 1:51 PM
    Monday, January 17, 2011 1:51 PM