
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?
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>>
--