Thread: I made a mistake? Where!?!

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    36

    I made a mistake!!!!

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    char get_first(void);
    int main(void)
    {
    
    char line1[40];
    char line2[40];
    char line3[40];
    char ch;
    int i;
    int j;
    int ln;
    int logic;
    int logic2;
    int num1;
    int num2;
    const char tokseps[]="+-/*";
    char * pt, * pt2;
    
    printf("Welcome To The Arithmetic Expression Evaluation Program!");
    ch='Y';
    while(ch != 'N')
       {
          printf("Enter The Arithmetic Expression:");
          gets(line2);
          j=0;
          for (i=0; i < 40; i++)
          if (!isspace(line2[i]))
                {
                   line1[j]=line2[i];
                   line3[j]=line2[i];
                   j++;
                }
    
    
    pt=strtok(line1, tokseps);
           pt2=strtok(NULL, tokseps);
           if(pt2==NULL)
           printf("%s Invalid Arithmetic Expression!", line2);
           else
              {
                 ln=strlen(pt);
                 logic=0;
                 for (i=0; i<ln; i++)
                    {
                       if (!isdigit(pt[i]))
                       logic=1;
                    }
           logic2=0;
           ln=strlen(pt2);
           for (i=0; i < ln; i++)
              {
                 if (!isdigit(pt2[i]))
                 logic2=1;
              }
           if ((logic==1) || (logic2==1))
           printf("%s Invalid Arithmetic Expression!",line2);
           else
              {
                 num1=atoi(pt);
                 num2=atoi(pt2);
                 ln=strlen(pt);
                 if ((line3[ln])=='+')
                    printf("the sum of %d and %d is %d.", num1, num2, (num1+num2));
                 else if ((line3[ln])=='-')
                    printf("the sum of subtraction %d from %d is %d.", num2, num1, (num1-num2));
                 else if ((line3[ln])=='*')
                    printf("result of multiplication of %d of %d is %d.", num1, num2, (num1*num2));
                 else if ((line3[ln]=='/')
    {
           if(num2==0)
              printf("error. division by zero!.");
           else
              printf("the result of division %d by %d is %d",num1, num2, (num1/num2));
    }
    }
    }
    
    printf("would you like to continue?");
           ch=get_first();
    }
     return 0;
    }
           char get_first(void)
    {
    int ch;
    ch=getchar();
    while (getchar ()!= '\n')
    continue;
    return ch;
    }
    Please someone tell me what's wrong with my program! These braces I put in bold are being highlighted as red when I type them in! I checked and they seem fine! But it's showing as red!
    Last edited by 98dodgeneondohc; 04-21-2005 at 12:02 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    else if ( (line3[ln])=='/' )
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    36
    Quote Originally Posted by Dave_Sinkula
    Code:
    else if ( (line3[ln])=='/' )

    thanks brotha!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mistake of using awk
    By lehe in forum Linux Programming
    Replies: 6
    Last Post: 04-02-2009, 04:41 PM
  2. Problem aligning floating point numbers
    By esbo in forum C Programming
    Replies: 4
    Last Post: 01-05-2009, 08:09 PM
  3. Whom do you blame for the mistake in Pres. Bush's State of the Union speech?
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 07-15-2003, 07:03 AM
  4. What was the first game you ever made?
    By jverkoey in forum Game Programming
    Replies: 0
    Last Post: 02-12-2003, 11:09 PM