Thread: help i cant get it working

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    Red face help i cant get it working

    i am new with c. i was using c++ before this. i dont get it why i cant get it to work with so many error. can someone show me the correct way.
    i was wondering which is the best function to use in order to prom a error message when an invalid character is entered then go back to the scanf function to enter again.
    thanks

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    One thing I noticed when opening in a syntax-highlighting text editor (SciTE)...some of your printfs have extra quotes.
    Last edited by rags_to_riches; 03-06-2008 at 10:10 AM. Reason: typo

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    Quote Originally Posted by rags_to_riches View Post
    One thing I noticed when opening in a syntax-highlighting text editor (SciTE)...some of your printfs have extra quotes.
    He is right. Also i think you like to do
    Code:
        do
         {
           printf("enter option here: ");
           scanf("%d",&option);
           switch ( option )
    instead of
    Code:
    printf("enter option here: ");
    	scanf("%d",&option);
    	do
    	{
    
    	switch ( option )
    Last edited by SONU; 03-06-2008 at 10:32 AM.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    When I compile your program using VC++ 6.0, I get 102 errors, not to mention the warnings. Your #define statements won't cut the mustard. Just remove the #define and that should take care of all those errors and warnings. You also will have to remove the '+' and '-' signs. Maybe define as "char APlus[2]", etc.

    Also "Score * 3 = english_language;" is backwards --- "english_language = Score * 3;"

    That should get you started. You have other errors to fix as well.

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Way to many warnings/errors with this. Also what is your intent on:

    Code:
    while( option > 3 || option < 3 );
    Your options for your switch are for 1,2,3.

    Also your function grade_value() is not declaried. Your only function outside of main() is

    Code:
    double Grade ( char &Grade )

    Again, your scanf() is expecting a %s, string, yet you are assigning to &Grade which is of type char. This gives only a warning, but is not clean code.

    Have you compiled this and have seen these warning and errors yourself?

    As already mentiond your #defines are causing most of your troubles, which gives syntax errors with the use of '['.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    i have made it more organized

    ive taken you guy's advice thanks alot. and this is an revised version of the program. but i still have errors. can anyone help me with it. i still can't figure out how to solve it. thanks. if possible correct the source code and post it up. thanks alot.
    Last edited by navarrowee; 03-06-2008 at 12:01 PM. Reason: ive change it and reduce the errors but still there is errors to be solved

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Remove all those defines.
    Code:
    //#define char f;
    Local function definitions are illegal (INDENT PROPERLY and you wouldn't have this problem!):
    Code:
    void Sem_1 ( void )
    Void is not necessary for inside argument lists in C++ (which is what you're compiling it as):
    Code:
    void Sem_1 ()
    Due your indentation problem, the code is all in the wrong places because you missed a }:
    Code:
    	do
    	{
    
    		printf("enter option here: ");
    		scanf("%d",&option);
    		switch ( option )
    		{
    		case 1:
    
    			system ( "cls" );
    			Sem_1();
    
    			break;
    
    		case 2:
    
    			system ( "cls" );
    			Sem_2();
    
    			break;
    
    		case 3:
    
    			system ( "cls" );
    			Sem_3();
    
    			break;
    		}
    	}
    	while( option > 4 || option < 4 ); 
    	return 0;
    }
    Missing ;
    Code:
    int back_1;
    writing_for_mass_communication: undeclared variable.
    Code:
    writing_for_mass_communication = Score * 3;
    Code:
    Score * 3 = computer_studies;
    Perhaps you intended:
    Code:
    computer_studies = Score * 3;
    Missing ;
    Code:
    printf("press 0 to go back to option menu");
    Code:
    scanf("%d", &back_1);
    computer_studies: undeclared variable.
    Code:
    computer_studies = Score * 3;
    gpa_sem_1: undeclared variable.
    Code:
    cgpa_sem_2 = ( ( gpa_sem_1 + gpa_sem_2 ) / 2 );
    Missing ;
    Code:
    printf("press 0 to go back to option menu");
    scanf("%d", &back_2);
    gpa_sem_1, gpa_sem_2: undeclared variables.
    Code:
    cgpa_sem_3 = ( ( gpa_sem_1 + gpa_sem_2 + gpa_sem_3 ) / 3 );
    Missing ;
    Code:
    printf("press 0 to go back to option menu")
    scanf("%d", &back_3)
    Completely wrong in all sorts of ways and expectations.
    Code:
    	if (strcmp( Grade, A+ || a+ == 0 ))
    	{
    		Score += 4.00;
    	}
    	else if (strcmp( Grade, A- || a- == 0 ))
    	{
    		Score += 3.70;
    	}
    	else if (strcmp( Grade, B+ || b+ == 0 ))
    	{
    		Score += 3.30;
    	}
    	else if (strcmp( Grade, B || b == 0 ))
    	{
    		Score += 3.00;
    	}
    	else if (strcmp( Grade, B- || b- == 0))
    	{
    		Score += 2.70;
    	}
    	else if (strcmp( Grade, C+ || c+ == 0 ))
    	{
    		Score += 2.30;
    	}
    	else if (strcmp( Grade, C || c == 0 ))
    	{
    		Score += 2.00;
    	}
    	else if (strcmp( Grade, D || d == 0 ))
    	{
    		Score += 1.00;
    	}
    	else if (strcmp( Grade, F || f == 0 ))
    	{
    		Score += 0.00;
    	}
    	else
    	{
    		printf( "invalid grade\n" );
    		printf( "please enter again: " );
    	}
    Score: undeclared variable.
    Code:
    Score += 4.00;
    Uninitialized variables public_speaking and writing_for_mass_communication used.
    Code:
    gpa_sem_1 = ( ( english_language + public_speaking + principles_of_accounting + 
    principles_of_economics + general_mathematics_1 + computer_studies ) / 18 );
    You obviously know nothing about C or C++. Go back to school. This isn't a playground.
    Make a real effort in making a program and start of small. When you've mastered the basics, come back and we'll help you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    5

    Question this is an revised program but it has 3 errors which i dont really know how to solve

    how do i solve the three unresolced external symbols. i know it has got to do i with the function calling. but not sure how to solve it.
    any advice on what logic should i use to do error warnings and go back to the previous data entry.
    i am feeling the error is from this part but i am not sure what is it trying to point out.

    //function prototype
    double sem_1 ( void );
    double sem_2 ( double );
    double sem_3 ( double, double );

    thanks for you help.
    Last edited by navarrowee; 03-07-2008 at 02:58 AM.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you post WHICH symbols are unresolved, then that would help us quite a bit.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Why your c file has cpp extention? cpp is for C++, C-file in general have to have c-extention
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C code can be compiled as C++ code, and to be honest, I would recommend it that way.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Elysia View Post
    C code can be compiled as C++ code, and to be honest, I would recommend it that way.
    I wouldn't. If you want to write C++ - do it. If you are using C - use it. Do not mix 2 different languages in one compilation unit
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    But if i have C code i need to use in C++, would the recommended way be linking the object files to a library and #including their interface? When i inline functions in C header files, either as #define Macros or using the inline directive, then there are issues i should care for? I have not used C++ that much, but am not a total stranger, and i would like to know what is the best way to make both happy.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  14. #14
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Elysia View Post
    C code can be compiled as C++ code
    That's not entirely true, this is legal C code, but it won't compile on a C++ compiler for obvious reasons:

    Code:
    int class = 0;
    This ofcourse applies to all keywords in C++ that C doesn't have. Also, why would you recommend a C++ compiler for C code?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    C++ has a stronger type-checking than C, so that would be one reason to compile code with C++ compiler even tho' the code itself is C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM