Thread: i need a debugger badly...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    38

    i need a debugger badly...

    Code:
    #include <stdio.h>
    #include <math.h>
    
    main()
    {
      double first_a, first_b, second_a, second_b, ans1, ans2, ans3, ans4, ans5, ans6;
      printf("Test Complex Number Arithmetic");
      printf("\n");
      printf("Enter the first complex number in the form - real, imaginary - --> (");
      scanf(" ( %lf , %lf )", &first_a, &first_b );
      printf("\n");
      printf("Enter the second complex number in the form - real, imaginary - --> (");
      scanf(" ( %lf , %lf )", &second_a, &second_b );
      printf("\n");
      ans1 = (first_a + second_a, first_b + second_b);
      ans2 = (first_a - second_a, first_b - second_b);
      ans3 = (first_a * second_a, first_b * second_b);
      ans4 = (first_a / second_a, first_b / second_b);
      ans5 = (sqrt(first_a), sqrt(first_b));
      ans6 = (sqrt(second_a), sqrt(second_b));
      printf("Results:  (%lf) + (%lf) = (%lf)  (%lf) + (%lf) = (%lf)  (%lf) + (%lf) = (%lf)  abs(%lf) + (%lf) = (%lf)   abs(%lf) + (%i) = (%i)", first_a, first_b,
    second_a, second_b, ans1, first_a, first_b, second_a, second_b, ans2, first_a, first_b, second_a, second_b, ans2, first_a, first_b, second_a, second_b, ans3, first_a,$
    
    return 0;
    }
    Last edited by newcstudent; 10-12-2006 at 01:16 AM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Please explain what is wrong if you can. Any information that you have, like a sample run of your program, your compiler, your OS, and your expectations are valuable.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    38
    Code:
    #include <stdio.h>
    #include <math.h>
    
    main()
    {
      double a1, b1, a2, b2, a_ans1, b_ans1, a_ans2, b_ans2, a_ans3, b_ans3, a_ans4, b_ans4, a_ans5, b_ans5, a_ans6, b_ans6;
      printf("Test Complex Number Arithmetic");
      printf("\n");
      printf("Enter the first complex number in the form - real, imaginary - -->");
      scanf(" ( %lf , %lf )", &a1, &b1 );
      printf("\n");
      printf("Enter the second complex number in the form - real, imaginary - -->");
      scanf(" ( %lf , %lf )", &a2, &b2 );
      printf("\n");
      a_ans1 = (a1 + a2);
      b_ans1 = (b1 + b2);
      a_ans2 = (a1 - a2);
      b_ans2 = (b1 - b2);
      a_ans3 = (a1 * a2);
      b_ans3 = (b1 * b2);
      a_ans4 = (a1 / a2);
      b_ans4 = (b1 / b2);
      a_ans5 = sqrt (a1);
      b_ans5 = sqrt (b1);
    
      printf("Results:\n"
             "(%lf + %lf) (%lf + %lf) = (%lf), (%lf)\n"
             "(%lf + %lf) (%lf + %lf) = (%lf), (%lf)\n"
             "(%lf + %lf) (%lf + %lf) = (%lf), (%lf)\n"
             "(%lf + %lf) (%lf + %lf) = (%lf), (%lf)\n"
             "(%lf + %lf) (%lf + %lf) = (%lf), (%lf)\n",
             a1, b1, a2, b2, a_ans1, b_ans1
             a1, b1, a2, b2, a_ans2, b_ans2
             a1, b1, a2, b2, a_ans3, b_ans3
             a1, b1, a2, b2, a_ans4, b_ans4
             a1, b1, a2, b2, a_ans5, b_ans5);
    
    return 0;
    this is my updated code... i need it to read something like the below...
    but i get a compiler error

    assignment3.c: In function `main':
    assignment3.c:33: error: syntax error before "a1"




    Test Complex Number Arithmetic

    Enter the first complex number in the form ( real, imaginary ) --> (1.0, 1.0)

    Enter the second complex number in the form ( real, imaginary ) --> (2.1, 3.4)

    Results:

    (1.000000, 1.000000) + (2.100000, 3.400000) = ( 3.100000e+000, 4.400000e+000)
    (1.000000, 1.000000) - (2.100000, 3.400000) = (-1.100000e+000, -2.400000e+000)
    (1.000000, 1.000000) * (2.100000, 3.400000) = (-1.300000e+000, 5.500000e+000)
    (1.000000, 1.000000) / (2.100000, 3.400000) = ( 3.443957e-001, -8.140263e-002)
    abs(1.000000, 1.000000) = (1.414214)
    abs(2.100000, 3.400000) = (3.996248)
    Last edited by newcstudent; 10-12-2006 at 03:36 AM.

  4. #4
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Code:
     printf("Results:\n"
             "(%lf + %lf) + (%lf + %lf) = (%lf, %lf)\n"
             "(%lf + %lf) - (%lf + %lf) = (%lf, %lf)\n"
             "(%lf + %lf) * (%lf + %lf) = (%lf, %lf)\n"
             "(%lf + %lf) / (%lf + %lf) = (%lf,  %lf)\n"
             "(%lf + %lf) (%lf + %lf) = (%lf, %lf)\n",
             a1, b1, a2, b2, a_ans1, b_ans1,
             a1, b1, a2, b2, a_ans2, b_ans2,
             a1, b1, a2, b2, a_ans3, b_ans3,
             a1, b1, a2, b2, a_ans4, b_ans4,
             a1, b1, a2, b2, a_ans5, b_ans5);
    Note the ',' on the end of each variable list staring a1, ...

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    a1, b1, a2, b2, a_ans1, b_ans1
    a1, b1, a2, b2, a_ans2, b_ans2
    a1, b1, a2, b2, a_ans3, b_ans3
    a1, b1, a2, b2, a_ans4, b_ans4
    a1, b1, a2, b2, a_ans5, b_ans5);

    Add more commas
    Each parameter needs a comma, even those at the end of a line

    Edit: beaten
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    38
    thanks. it helped alot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a C# program with a manifest file to run in the debugger
    By Xarzu Athanasop in forum C# Programming
    Replies: 0
    Last Post: 01-18-2008, 06:34 PM
  2. executing from debugger
    By hedwin in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2007, 04:05 PM
  3. Replies: 3
    Last Post: 07-24-2007, 04:25 PM
  4. MSVC++ Debugger (it kills me)
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 06-29-2002, 07:37 PM