Thread: 0 failures but does not complile. Does anyone know what is happening?

  1. #1
    Registered User
    Join Date
    Aug 2012
    Location
    United States
    Posts
    8

    0 failures but does not complile. Does anyone know what is happening?

    Hello I wrote a few hours earlier and Ive been working on it. I am trying to write a calculator program the output should be:

    1. addition
    2. subtraction
    3. multiplicaiton
    4. division
    5. Exit

    please select an operand?
    please enter two numbers separated by a space: ?
    the result of %f and % f is %f.

    I've tried for a while. I am not sure about the while loop. Any help woould be very much appreciated! I can't attach the code below so i copied pasted it:

    Code:
    #include<stdio.h>
    float choice;
    float result;
    float num1, num2;
    int get_choice();
    int main()
    {
    {
    float num1, num2;
    int choice;
    float result;
    do
    {
    printf("Welcome to Colleen Gonzales's Handy Calculator");
    printf("1. Addition\n");
    printf("2. Subtract\n");
    printf("3. Multipilcation\n");
    printf("4. Division\n");
    printf("5. Exit\n");
    printf("\n\nPlease pick an operation.\n");
    scanf("%f", &choice);
    }
    while( (choice = 1,2,3, 4 , 5) );
    printf("Please choose two numbers seperated by a space:");
    scanf("%f %f", &num1, &num2);
    return 0;
    }
    { 
    float num1, num2, result;
    int choice;
    while( (choice=get_choice()) !=5)
    {
    switch (choice)
    {
    case 1 : result = num1 + num2;
    break;
    case 2 : result = num1-num2;
    break;
    case 3 : result = num1 * num2;
    break;
    case 4 : result = num1/num2;
    break;
    case 5 : printf("Goodbye");
    break;
    default :printf("Please respond with 1, 2, 3, 4, or 5\n");
    break; /*end of switch*/
    }
    }
     
    printf("The result of %f and %f is %.2f\n", &num1, & num2, &result);
    return 0;
    }
    }
    



  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Code:
    while( (choice = 1,2,3, 4 , 5) );
    You can't do that.
    You've just written something that you'd like to be how you could write such a thing, but C does not have such shortcuts for doing what you want in that sort of way. What you want to do is to loop while the number entered is less than 1 or the number entered is greater than 5.

    Also, if the user selects 5, then why would you still ask for two numbers?
    And if they had entered 1 to 4, then you just terminate the program after getting the input.

    As much as you may have intended to do so, you don't actually have a function called get_choice in the code you have posted. All you have is an unused function prototype.

    Your best option is copy and paste the code as plain-text, and make sure that the indentation is preserved. It's horrible reading code with no indentation.

    Edit: Dammit, why did you start a second thread?! I found your other one after replying to this one.
    Last edited by iMalc; 08-20-2012 at 09:54 PM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Aug 2012
    Location
    United States
    Posts
    8
    okay sorry ill try to delete this one...i did try to add. But it wasnt letting me.
    Last edited by colleeng; 08-20-2012 at 10:11 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    0 failures but does not complile. Does anyone know what is happening? - Dev Shed
    Pick a forum, and pick a thread
    If you post all over the place, you'll just ........ everyone off and get confusing mixed messages.

    And when you copy/paste code, make sure you "paste as text".
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is happening here?
    By kermit in forum C Programming
    Replies: 4
    Last Post: 02-01-2009, 11:59 AM
  2. _beginthreadex does not complile
    By Devil Panther in forum Windows Programming
    Replies: 22
    Last Post: 12-13-2006, 07:51 AM
  3. Reasons & Workarounds For ostream Failures
    By Tronic in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2005, 02:03 PM
  4. How do you complile a .pc file?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 04-29-2002, 02:35 PM
  5. assertion failures
    By edwardtisdale in forum C++ Programming
    Replies: 1
    Last Post: 01-17-2002, 04:07 AM