473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to use isDigit?

im having a program.I want it to check if it is a character or integer is entered
where shall i put the isDigit and how to use?i put it as highlighted below but got error.

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

int is_prime( int input, int z);

int main (void)
{
int input;
char on;
char option;

printf("Press <enter> to continue\n");
scanf("%c",&on);
system("cls");
fflush(stdin);

//if(isdigit(input))

printf("Please enter a number:");
scanf ("%d",&input);

fflush(stdin);

if( is_prime(input,2))
printf("\nThis number is PRIME\nThank you.\a\a\n\n");
else
printf("\nThis number is NOT PRIME\nThank you.\a\a\n\n");

do{
printf("Do you still want to continue?(Press 'Y' for YES or 'N' for No)\n");
scanf ("%c",&option);

if(option=='Y' || option=='y')
{
system("cls");
return main();
}
else if(option=='N' || option=='n')
return 0;
else
printf("Incorrect input.The program will quit now.\n\n");
}while(option=='Y' || option=='y' || option=='n' || option=='N');
}

int is_prime( int input,int n)
{
if( input < 2 )
return 0;

else if( input == 2 )
return 1;

else
if( !(input % n ))
return 0;
else if(n < input-1)
return is_prime(input, n+1);
else
return 1;
}
Feb 27 '09 #1
1 4360
Problem solved.
if(!(isdigit(input)))
fflush(stdin);
if( is_prime(input,2))
printf("\nThis number is PRIME\nThank you.\a\a\n\n");
else
printf("\nThis number is NOT PRIME\nThank you.\a\a\n\n");

do{
printf("Do you still want to continue?(Press 'Y' for YES or 'N' for No)\n");
scanf ("%c",&option);

fflush(stdin);

if(option=='Y' || option=='y')
{
system("cls");
return main();
}
else if(option=='N' || option=='n')
return 0;
else
{
printf("Incorrect input.The program will quit now.\n\n");
return 0;
}
}while(option=='Y' || option=='y' || option=='n' || option=='N');
Feb 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James Gregory | last post by:
I read that the argument to isdigit() can be "an integer whose value is representable as an unsigned char, or the value of the macro EOF.". This seems to say that it should work for values greater...
15
by: Carramba | last post by:
hi! I am trying to confirm if input is digit, so I thought it would by easy to do it with with isdigit() funktion, but how do I pass arrays to it if the imput is more then 1 sign? #include...
7
by: Per Rollvang | last post by:
Hi All! I have a problem with hex strings when using Char.IsDigit(). The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F... MSDN tell me that: Indicates whether a...
2
by: Jefe | last post by:
Hi Group Could you please explain to me what's the difference between Chars.IsDigit and Chars.IsNumber? Regards,
10
by: mdh | last post by:
Could I get some help as to understanding why I am not getting a result I expect. #include <stdio.h> #include <ctype.h> int main (){ int i,j,k,c; i=9;
16
by: skneife | last post by:
Doeas any know the simplest way for create this type of function: bool result = IsDigit(string s); Sam
3
by: MooMaster | last post by:
N00b question alert! I did a search for isdigit() in the group discussion, and it didn't look like the question had been asked in the first 2 pages, so sorry if it was... The manual...
2
by: bozo789 | last post by:
Hi Forum, First let me begin by stating I am a student and have read the proper posting procedure concerning students. I am a begginer learning with the Miracle C Work Bench. I know my code is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.