www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/07/11:16:06

From: jaxonjr AT my-deja DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: How to fix?
Date: Sun, 07 May 2000 15:47:14 GMT
Organization: Deja.com - Before you buy.
Lines: 49
Message-ID: <8f435u$j50$1@nnrp1.deja.com>
NNTP-Posting-Host: 166.102.225.165
X-Article-Creation-Date: Sun May 07 15:47:14 2000 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95)
X-Http-Proxy: 1.1 x33.deja.com:80 (Squid/1.1.22) for client 166.102.225.165
X-MyDeja-Info: XMYDJUIDjaxonjr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

How do I fix this?
case '/' works but case '*' doesn't.
TIA.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    double n1;
    double n2;

    if(argc > 3)
    {
        n1 = atof(argv[1]);
        n2 = atof(argv[3]);

	switch(argv[2][0])
	{
            case '/' :
                if(n2 == 0)
                {
                    printf("Cannot divide by zero.\n");
                    break;
                }

		printf("%f / %f = %f\n", n1, n2, n1 / n2);
		break;

	    case '*' :
		printf("%f * %f = %f\n", n1, n2, n1 * n2);
		break;

	    default :
		break;
	}

    }

    return 0;
}


--
Peace!


Sent via Deja.com http://www.deja.com/
Before you buy.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019