Thread: Second program

  1. #31
    Registered User
    Join Date
    Jul 2003
    Posts
    49
    well thanks anyway
    i just got to a part in the book that says to much programming in
    one day makes you c sick.
    I know, cheesy
    but true
    i'll try again tomorrow

  2. #32
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    Originally posted by Elite
    i didnt think it would be so difficult to write such a simple program
    maybe i should stick with gamestudio
    what compiler r u using?
    GCC 1 and it isn't hard but I suck at this and I'm not used to edting other peoples code.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  3. #33
    Registered User dbyte's Avatar
    Join Date
    Jul 2003
    Posts
    15
    Elite,
    Below your # include statements you initialize the function as "sub", but everywhere else in your code it's referred to as "subb". I'm not sure if this is the reason for your specific error message(s), but thought you should know.

  4. #34
    Registered User dbyte's Avatar
    Join Date
    Jul 2003
    Posts
    15
    Okay, finally got the (altered) code working:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    void subb()
    {
         int r;
         int t;
         int q;
         printf("Please enter a number the press enter : ");
         scanf("%d",&r);
    	 printf("What would you like me to add to that number? : ");
    	 scanf("%d",&t);
         q=r+t;
    	 printf("%d plus %d equals %d",r,t,q);
         printf("\n");
         system("PAUSE");
    }
    
    void nam()
    {
        char x[20];
        char kate[] = {"kate"};
        printf("Please enter your name : ");
    	scanf("%s",x);
        if(strcmp(x, kate) == 0)
    	printf("Thats a great name!!!!");
        else
                    printf("Ha, what a crap name!!!");
        printf("\n");
        system("PAUSE");
    }
    
    int main()
    {
        char test = 'a';
    	char c;
    	printf("Hi, I am the name genie and i am good at addition\nWhat would you like to do?\nPress A to add or B to get insight into your name");
       scanf("%c",&c);
        if(c == 'a')
            subb();
    	else
            nam();
    	return 0;
    }
    I added the system("PAUSE") lines so you could view the output before your window closes, in case you're using a Windows machine like I am & not calling the .exe from the command prompt in DOS. Also, I usually initialize the functions before main(). Not sure if that's "good form", it's just the way I am learning to do it. Hope this helps, from 1 student to another.

  5. #35
    Registered User
    Join Date
    Jul 2003
    Posts
    49
    Hey thanks dbyte but i still get the same error so it is definately the compiler, i'll try one of those free compilers and see what i get.
    Thanks again

  6. #36
    Registered User
    Join Date
    Jul 2003
    Posts
    49
    I just reinstalled msvc++ and the code works fine now.
    Maybe i accidentally changed a header file or something
    i get an undeclared identifier with the system bit so i just commented it out but it works without it
    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM