3 Replies - 4731 Views - Last Post: 24 June 2008 - 12:07 PM Rate Topic: -----

#1 DiceK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-June 08

C++ Word finder program (need help) ASAP

Post icon  Posted 23 June 2008 - 01:23 PM

I am learning C++. I need to write a program where the program will attempt to find words that begin with entered character and have all pairs of adjacent characters the specified distance apart. Here is as example of what I need the program to do:

Enter the first character: a
Enter the distance: 15
Is ap a word? n
Is ape a word? y
Found a 3-letter word!

or

Enter the first character: p
Enter the distance: 2
Is pr a word? n
Is prt a word? n
Is prtv a word? n
Is prtvx a word? n
Is prtvxz a word? n
Is prtvxzb a word? n
Is prtvxzbd a word? n
Is prtvxzbdf a word? n
Is prtvxzbdfh a word? n
Is prtvxzbdfhj a word? n
Is prtvxzbdfhjl a word? n
Is prtvxzbdfhjln a word? n
No words were found that meet the given qualifications.


This is what I have so far. I need to use ( while, do/while, for and/or if/else) but not sure how to do it. i know the distance need to be between 1 and 25. Can someone help me. I need this by 6.25.08.


Here is what I have thus far.

#include<iostream>
using std::cout;
using std::cin;

int main()
{
char  letter, new_letter, firstletter, lastletter, next;
int offset, original_offset, first='a';


cout << "Enter a letter ";
cin >> letter;
original_offset = letter - 'a';
cout << "How far away ";
cin >> offset;
    
cout << "Is " << letter <<  "  a word?";
if (firstletter != lastletter)
        
cout << " Is " << next << " a word?:";

return 0;
}



Thanks

** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Word finder program (need help) ASAP

#2 DiceK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-June 08

Re: C++ Word finder program (need help) ASAP

Posted 23 June 2008 - 03:03 PM

anybody had a chance to look at the problem yet?
Was This Post Helpful? 0
  • +
  • -

#3 Crowbar6  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 07-June 08

Re: C++ Word finder program (need help) ASAP

Posted 23 June 2008 - 06:59 PM

Not much, but this may help you get a start.

I would use for loops in conjunction with resizable arrays (using dynamic memory allocation (pointers))

ask for the distance before entering the loop:

int distance;
cout << "Enter the distance: ";
cin >> distance;
int *offset = new int[distance];

for (int i = 0; i < distance; i++)
{
	//code to ask questions and what not goes here

	//check user's answer

   if (UserInput = 'Y' || UserInput = 'y')
   { 
		cout << "Found a " << offset[i] + 1 << " letter word!" << endl;
		return 0;
   }
  // else is implied here, because if the user inputs anything aside from Y or y
  // it skips the if statement and heads back to the top.
}

cout << "Could not find any valid words!" << endl;
return 0;



That's not complete but that should "point" you in the right direction. (Sorry, dry programming humor)

-Crowbar
Was This Post Helpful? 0
  • +
  • -

#4 DiceK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-June 08

Re: C++ Word finder program (need help) ASAP

Posted 24 June 2008 - 12:07 PM

View PostDiceK, on 23 Jun, 2008 - 03:03 PM, said:

anybody had a chance to look at the problem yet?



thanks for the reply, was wondering if anyone was going to help.

sadly we Can not use array to write the code.

Any other ideas?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1