Thread: If else end

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    If else end

    Ok I made this converter for my friend so that he can see how much things are in Canadian money compared to American money and it works, but what I would like to do is have it so it keeps looping untill someone enters a value lower than 1, and if they do it exits. This is what I have so far:

    Code:
    #include <stdio.h>
    
    float userNum=0;
    float userNumA=0;
    #define US  1.57551;
    
    int main(void)
    {
    	printf("This is a currency converter, from American dollars to Canadian\n");
    	printf("Please enter the american amount now: ");
    	scanf("%f", &userNum);
    
    	if(userNum>=1)
    	{
    		userNumA =userNum * US;
    		printf("American amount:%f  Canadian amount: %f\n\n",userNum, userNumA);
    	
    	}
    	else
    	{
    		printf("Thank you for using my converter\n\n");
    	}
    	return 0;
    }
    I had originally thought of puttin a break command in the else part of if else, but that is not allowed, and I couldn't think of a way to do it with a do or for statement without it repeating over and over again, can someone help and thanks.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You can do it like this:

    Code:
    int main(void)
    {
       while(1)
       {
          printf("This is a currency converter, from American dollars to Canadian\n");
          printf("Please enter the american amount now: ");
          scanf("%f", &userNum);
    
          if(userNum>=1)
             printf("American amount:%f  Canadian amount: %f\n\n",userNum, userNum * US);
          else
             break;
       }
              
       printf("Thank you for using my converter\n\n");
       return 0;
    }
    Last edited by Cshot; 08-12-2002 at 12:19 PM.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Re: If else end

    edit : beat me to it.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    cap
    Guest

    Unhappy

    I tried out your code and it had a whole bunch of those 'undeclared identifier' errors for things like printf and scanf. Also what does while(1)do?? Is that how it loops untill someone enters a number less than 1?

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > while(1)

    This is always true, so it's an inifinite loop - the break statement in there means it breaks out of the loop when the condiiton is met (the input's less than 1).

    As for the other error - you remembered to put the libs in, right? You didn't just copy and paste the code?

  6. #6
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Ok I got it, I just put the while(1) on my original code and moved the break in and it works, thanks a lot .
    Last edited by CAP; 08-12-2002 at 01:28 PM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    LAME("Salem")//for Googling people to death
    Well if most people would simply pull their heads out of their rectums, we wouldn't have to "google them to death". Most people, like you apparently, don't ever want to do any work themselves and just show up here expecting us to gleefully hand out the answers to every single homework / simple question without them so much as lifting a finger.

    Welcome to the RealWorld(TM). Get off your collective asses and put some effort into your problem for a change.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Most people, like you apparently, don't ever want to do any work themselves and just show up here expecting us to gleefully hand out the answers to every single homework / simple question without them so much as lifting a finger.
    Quzah.
    I don't know if you are talking to me or not...but this is not an assignment, I don't go to a computer school, take any classes, or learn from anyone person(with the exception of this board of course). It is not from a book and all I asked was how to make it a little bit better, it worked just fine but I wanted to make it better.

    If not though pay no attention to the above.

    P.S. I do have friends who do use some of these truly simple programs and they are not made up and not for a class as mentioned above, thank you.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, I quoted the person I was talking to.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Ya I considered that, which is why I put the do not bother with stuff above thing, but I also assumed that my question was pretty basic, and I mean within the realms of printf("") but whatever, thanks for clearing it up.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  11. #11
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: If else end

    damn canadians

    Code:
    #include <stdio.h>
    
    float userNum=0;
    
    int main(void)
    {
        printf("This is a currency converter, from Canadian dollars to American\n");
        printf("Please enter the canadian amount now: ");
        scanf("%f", &userNum);
        printf("American amount:%f  Canadian amount: %f\n\n", 0.0, userNum);
        return 0;
    }
    hello, internet!

  12. #12
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Hey come on, I am Canadian ...of course lol. I take it you are french? are you in Quebec or France or just speak french??
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Modify to make Doubly Linked List
    By Dampecram in forum C Programming
    Replies: 10
    Last Post: 11-03-2008, 07:25 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  4. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM