Friday, July 31, 2009

I'm writing an age program in numereic value. i want to know how to do an if staement to it?

i would like the if statement to be if the value added is not numeric for the program to say "no dumb *** numeric value".





# include %26lt;stdio.h%26gt;











int main()


{


int a,b,c,d,e;


("a=age\n");


("b=monthborn\n");


("c=currentmonth\n");


("d=currentyear\n");





printf("enter your age in numeric value \n");


scanf("%d", %26amp;a);


printf("enter the month you were born in numeric value \n");


scanf("%d", %26amp;b);


printf("enter current month in numeric value \n");


scanf("%d", %26amp;c);


printf("enter current year in numeric value\n");


scanf("%d", %26amp;d);


e=d-a;











if (b%26gt;c) {


e=e-1;


}


printf("you were born on %d \n",e);








}

I'm writing an age program in numereic value. i want to know how to do an if staement to it?
try this....








/* isdigit example */


#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;ctype.h%26gt;


int main ()


{


char str[]="1776ad";


int year;


if (isdigit(str[0]))


{


year = atoi (str);


printf ("The year that followed %d was %d.\n",year,year+1);


}


return 0;


}








hope this gives you the idea...
Reply:idk bout C


but in c++ it wold work like this





#include %26lt;iostream%26gt;


using namespace std;


int main();


int a,b,c,d,e;


cout%26lt;%26lt;" enter your age in numeric value\n";


cin%26gt;%26gt;a;


if ( a != # ) {


cout%26lt;%26lt;" no dumb *** numeric value\n";


}


cout%26lt;%26lt;"enter your birth month in numeric value\n";


cin%26gt;%26gt;b;


if ( b != # ) {


cout%26lt;%26lt;" no bumb *** numeric value\n";


}





continue this untill your done with D


then....





e=d-a;


if ( b%26lt;c){


e=e-1;


}


cout%26lt;%26lt;" you were born on " %26lt;%26lt; d"," %26lt;%26lt; e;


cin.get();


}











now i know your looking for c


but since this is all i know then this is all i can help


and i hope i helped a little


at least

mothers day flowers

No comments:

Post a Comment