HELP I am using Bloodshed's dev c++ and need help with this program before 7:30 tomorrow!
this is my code and i am trying to make a program that can check if a word is a digit word i.e have the letters ONE in order in the word. my errors are at the bottom please please help.
#include <string.h>
#include <stdio.h>
bool TextContainsADigit (char, char);
int main ()
{
char str[15];
char result;
char * pch ={
"ONE",
"TWO",
"THREE",
"FOUR",
"FIVE",
"SIX",
"SEVEN",
"EIGHT",
"NIGHT"
};
printf ("Please enter a word");
pch=strchr(str,'s');
while (pch!=NULL)
if(TextContainsADigit(str, digit){
printf ("not a digit number" ,pch-str+1); );
}else{
printf ("NO");
}
return 0;
}
bool TextContainsADigit (char* text, char* digit)
{
while (*digit != 0)
{
if (*text != *digit)
{
text++;
}
else
{
digit++;
text++;
}
C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp In function `int main()':
18 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp initializer for scalar variable requires one element
22 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp `digit' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
22 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp expected `)' before '{' token
#include <string.h>
#include <stdio.h>
usingnamespace std;
bool TextContainsADigit (char, char);
int main ()
{
string str; //You probably want to use an unlimited string
string result; //And unless you are using one letter as a result, you'll want a string for that too.
char * pch ={
"ONE",
"TWO",
"THREE",
"FOUR",
"FIVE",
"SIX",
"SEVEN",
"EIGHT",
"NINE"
};//Fixed your misspelling of NINE, and WTF are you trying to do here?
printf ("Please enter a word: ");
cin >> str; //Much easier
while (pch!=NULL) //I can't check anything past this right now, sorry...
if(TextContainsADigit(str, digit){
printf ("not a digit number" ,pch-str+1); );
}else{
printf ("NO");
}
return 0;
}
bool TextContainsADigit (char* text, char* digit) // For this, you're using arrays. You're not using the full thing.
{
while (digit != 0)
{
if (*text != *digit)
{
text++;
}
else
{
digit++;
text++;
}
if (*text == 0)
{
returnfalse;
}
}
returntrue;
}
You can use string::find() to help you, I can't check much code right now.
I dunno what happened i started off fine but i need to make a program that can tell if a word is a digit word and i dunno if that was any close.
thanks
Make sure you research string::find(), it will make your job 200% easier.
It should return something if it's true, another if it's false. (Look it up, I won't post any code)