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


How about telling us what the error is?

Ok, after spending 5 secs on your code I discovered this error:

Quote:
> printf ( "\n\n\n Your number equals.... %d , 1" );

You are missing an argument in the printf statement. It should be something
like:

printf ( "\n\n\n Your number equals.... %d", num );

--
Martin Rennix



Sun, 17 Apr 2005 05:47:33 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
Submitted by "Wakony  AKA Ben" to comp.lang.c:

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


You recently posted this to another newsgroup (or was it here
even?), and you got at least one reply there.  Basicly, your
functions are missing return types, your scanf() and printf()
calls are whacky, you include "stdio.h" instead of <stdio.h>.

--
Andreas K?h?ri               --==::{ Have a Unix: netbsd.org
                             --==::{ This post ends with :wq



Sun, 17 Apr 2005 10:10:04 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  
 
 [ 5 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 needs help please???

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

7. Newbie needs help! please

8. Newbie question: Need help please!

9. Newbie C programmer needs help Please!!!

10. NEWBIE NEEDS HELP PLEASE

11. newbie needs help (please)

12. newbie needs help (please)

 

 
Powered by phpBB® Forum Software