Help C newbie need help please 
Author Message
 Help C newbie need help please

Hey  Can anyone help me here. This is my program. Doesn't give any
problems in the editor or compiler, but when i execute it, it gives me

its under here |||||||||
               ^^^^^^^^^

#include "stdio.h"

#define QUIT 3    

int newopts( void );

int wasone;

int product(int x,int y);

int fromfar;

int fromcel;

main()
{
        int option = 0;

        while (option != QUIT)
        {
                option = newopts();

                if (option == 1)
                {
                        printf ( "\nPlease enter your number now:" );
                        scanf ( " %d , &fromfar " );
                        wasone = product(fromfar , 4);
                                printf ( "\n\n\n Your number equals.... %d , 1" );
                }

                else
                {
                        if (option == 2)
                        printf ( "\nPlease enter your number now:" );
                        scanf ( " %d , &fromcel " );
                        wasone = product(fromcel , 2);
                                printf ( "\n\n\n Your number equals.... %d , 1" );
                }
        }
        printf ( "You chose to Quit.. \n" );

        return 0;

Quote:
}

newopts()
{

        int optionsmenu = 0;

        do
        {

        /* Here is the Options Menu */
                printf ( " Options: \n" );

                printf ( " Convert From Farenhieght:=: 1 \n" );

                printf ( " Convert From Celcius:=: 2 \n" );

                printf ( " Enter Here: " );

                scanf( "%s", "&optionsmenu" );
        }while ( optionsmenu < 1 || optionsmenu > 2 );

        return optionsmenu;

Quote:
}

int product(int x,int y)
{
        return (x * y);
Quote:
}

--



Sun, 17 Apr 2005 05:00:13 GMT  
 Help C newbie need help please


Quote:
>Hey  Can anyone help me here. This is my program. Doesn't give any
>problems in the editor or compiler, but when i execute it, it gives me
>an error. Can anyone help me know what this is? if so email me


Sorry, I won't email you directly; ask questions here, read answers here.
You say your code doesn't give any "problems" in your compiler.  You
should turn up the warning level on your compiler; I get plenty of
"problems" when I try to compile your code:

dhcp-252[pts/7]:~/tmp$ gcc -ansi -pedantic -Wall -W -Werror -O2 t.c
cc1: warnings being treated as errors
t.c:18: warning: return type defaults to `int'
t.c: In function `main':
t.c:28: warning: too few arguments for format
t.c:31: warning: too few arguments for format
t.c:38: warning: too few arguments for format
t.c:41: warning: too few arguments for format
t.c: At top level:
t.c:56: warning: return type defaults to `int'
t.c: In function `newopts':
t.c:73: warning: writing into constant object (arg 2)

Quote:
>its under here |||||||||
>               ^^^^^^^^^

Under wear?

(Sorry...)

Fix the problems listed by gcc above (well actually, before you fix
them, figure out how to make your compiler complain about the same
things), then try back here again if you still have questions.

Also: please read the FAQ for this newsgroup:

    http://www.eskimo.com/~scs/C-faq/top.html

--Ben

--
--



Sun, 17 Apr 2005 06:03:05 GMT  
 Help C newbie need help please

Quote:
>Hey  Can anyone help me here. This is my program. Doesn't give any
>problems in the editor or compiler, but when i execute it, it gives me
>an error. Can anyone help me know what this is? if so email me

>its under here |||||||||
>               ^^^^^^^^^
>#include "stdio.h"

>#define QUIT 3    

>int newopts( void );
>int wasone;
>int product(int x,int y);
>int fromfar;
>int fromcel;

>main()

int main(void) to be portable.

Quote:
>{
>    int option = 0;

>    while (option != QUIT)
>    {
>            option = newopts();

>            if (option == 1)
>            {
>                    printf ( "\nPlease enter your number now:" );
>                    scanf ( " %d , &fromfar " );
>                    wasone = product(fromfar , 4);
>                            printf ( "\n\n\n Your number equals.... %d , 1" );

Your format string promises printf that there will be a second
parameter of type int.  You have omitted it.  This invokes undefined
behavior.  You probably meant to add `, wasone` after your closing ".

You should also add a \n following the 1 to insure the output is sent
to your display device or wherever stdout points.  Alternately you
could add a statement here `fflush(stdout);`

Quote:
>            }

>            else
>            {
>                    if (option == 2)
>                    printf ( "\nPlease enter your number now:" );
>                    scanf ( " %d , &fromcel " );
>                    wasone = product(fromcel , 2);
>                            printf ( "\n\n\n Your number equals.... %d , 1" );

Ditto.

Quote:
>            }
>    }

What will you do for a value other than 1, 2, or 3?

- Show quoted text -

Quote:
>    printf ( "You chose to Quit.. \n" );

>    return 0;

>}

>newopts()
>{

>    int optionsmenu = 0;

>    do
>    {

>    /* Here is the Options Menu */
>            printf ( " Options: \n" );

>            printf ( " Convert From Farenhieght:=: 1 \n" );

>            printf ( " Convert From Celcius:=: 2 \n" );

>            printf ( " Enter Here: " );

>            scanf( "%s", "&optionsmenu" );
>    }while ( optionsmenu < 1 || optionsmenu > 2 );

This code will not let you pass 3 back so you can never quit.

Quote:

>    return optionsmenu;
>}

>int product(int x,int y)
>{
>    return (x * y);

return is a statement type, not a function call.  The parentheses are
superfluous.

Quote:
>}

<<Remove the del for email>>
--



Tue, 19 Apr 2005 11:21:44 GMT  
 Help C newbie need help please

Quote:

> Hey  Can anyone help me here.

Your uses of scanf were not even close to correct.
I suggest studying Kernighan & Ritchie, "The C
Programming Language" (2nd Edition).
--



Tue, 19 Apr 2005 11:21:49 GMT  
 Help C newbie need help please
One thing I have learned from the past four months, which I spent
debugging a C program for my research -- ALWAYS run gcc with -ansi
-pedantic -Wall (or the equivalent "be anal" flags on your comipler.  It
may generate errors you don't care about, but at least that way you'll
see everything you _do_ care about.

ANdy
--



Tue, 19 Apr 2005 11:22:15 GMT  
 Help C newbie need help please
in comp.lang.c.moderated i read:

Quote:
>One thing I have learned from the past four months, which I spent
>debugging a C program for my research -- ALWAYS run gcc with -ansi
>-pedantic -Wall (or the equivalent "be anal" flags on your comipler.

oh, you mean:

-ansi -pedantic -O2 -Wall -W -Waggregate-return -Wcast-align -Wcast-qual
-Wnested-externs -Wpointer-arith -Wundef -Wshadow -Wbad-function-cast
-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
-Wconversion -Winline

toss in -Werror for some real fun.

--
bringing you boring signatures for 17 years
--



Tue, 19 Apr 2005 22:23:57 GMT  
 Help C newbie need help please


Quote:
> in comp.lang.c.moderated i read:

> >One thing I have learned from the past four months, which I spent
> >debugging a C program for my research -- ALWAYS run gcc with -ansi
> >-pedantic -Wall (or the equivalent "be anal" flags on your comipler.

> oh, you mean:

> -ansi -pedantic -O2

This specific part bears repeating: with many compilers, turning on
optimization will allow the compiler to produce warnings that would
not otherwise be generated.  These are typically warnings about using
variables before they've been initialized.

--
    Later,
    Jerry.

The universe is a figment of its own imagination.
--



Thu, 21 Apr 2005 00:16:53 GMT  
 Help C newbie need help please

Quote:
> in comp.lang.c.moderated i read:

> >One thing I have learned from the past four months, which I spent
> >debugging a C program for my research -- ALWAYS run gcc with -ansi
> >-pedantic -Wall (or the equivalent "be anal" flags on your comipler.

> oh, you mean:

> -ansi -pedantic -O2 -Wall -W -Waggregate-return -Wcast-align -Wcast-qual
> -Wnested-externs -Wpointer-arith -Wundef -Wshadow -Wbad-function-cast
> -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
> -Wconversion -Winline

> toss in -Werror for some real fun.

Are those all missing from -W -Wall?  I must read the gcc manual
some time.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!
--



Thu, 21 Apr 2005 00:18:33 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Help C newbie need help please

2. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

3. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

4. Please help!!!!Please help!!!!Please help!!!!

5. Newbie question: Need help please!

6. newbie needs help (please)

7. newbie needs help (please)

8. NEWBIE NEEDS HELP PLEASE

9. Newbie C programmer needs help Please!!!

10. Newbie needs help! please

11. Newbie question: Need help please!

12. Newbie needs help Please!!! :-)

 

 
Powered by phpBB® Forum Software