C++ how do I add chacters without using arrays and strings

Have a program have everything finsihed except one thing
i have to print letters without useing arrays or strings or 26 variables
can use for, while, do, if/else loops

has a starting letter
has a number that instructs it to find the next letter x number of spaces down

etc
letter='a';
number = 2;
new_letter=letter+number;
cout << letter << " " <<new_letter;

prints a c

word=letter+new_letter (just adds need something that will print and hold the actual letters)

asks is that a word if no
prints ac e

repeat until word is found or cycle back to the starting leter

where i am having the issue is printing the word or the previous letters
before the new_letter
ie
i can get it to print 2 letters
ac
ae
ag

but cant get it to print
ac
ac e
ace g

I dont want the code to make it work just some pointers on where I am going wrong. First semester in c++. thinking now taking a summer class in this might have been a bad move.
anyway any pointers will be very much appreciated

code so far
attached as code snippet

#include<iostream>
 
using std::cin;
using std::cout;
 
int main()
{
	char answer, letter, new_letter;
	char word=0;
	
	int number=0, count=0;
	
	
	cout << "\nWord Finder. User will enter a Letter then a number."
		 << "\nWord finder will move through the alphabit to the ."
		 << "\nnext letter by a count of the number you entered."
		 << "\nAsking User if the combination is a word or not.\n";
		 
	do{
		cout << "\nEnter a letter. ";
		cin >>  letter;
		letter=tolower(letter);
	  }while (!(letter >= 'a' && letter <= 'z'));		
	    cout << letter;
		
	do{
		cout << "\nEnter a number From 1 to 26.\n";
		cin >> number;
	}while (!(number >=0 && number <=26));
		cout << number;
		
	new_letter=letter+number;
	
	do{
		cout << "\nIS "<< letter << new_letter << " a word? y for yes. n for no ";
		cin >> answer;
		++count;
		letter = letter+new_letter;
		new_letter=new_letter+number;
		
		answer=tolower(answer);
    }while(answer != 'y' && count <10 && answer == 'n');
 
	if (count <10)
		cout << "\nFound a Word in "<< count<<" trys.";	
		
		else
			cout << "\nNo Words Found!!";
		
	return 0;
}

Open in new window

windshireAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
Just a quick note on that code (after quickly looking over it) :

>> if (answer='n')

the = operator is the assignment operator, not the comparison operator. The latter is ==, so you probably meant :

        if (answer == 'n')



No arrays, no strings, no recursive functions. That is extremely limiting for this kind of assignment. I would verify those restrictions with the teacher if I were you.
0
 
Infinity08Commented:
>> word=letter+new_letter (just adds need something that will print and hold the actual letters)

That's called a string :) Why can't you use it ?

Can you post the exact text of the assignment ?
0
 
windshireAuthor Commented:
we can only use what he has covered. and he has not covered string assignments. Yes this is what has me stumped. I am asking same question on his forum

i am capable of doing it with a string and array just cant figure out how to do it without using those and not making a ton of variables and if/else statments

/boggle but can only use what has been covered in class and strings have not been. Only other thing i can thin of is maybe he thinks he covered it.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Infinity08Commented:
You could always go for a recursive function, but that's a bit overkill imo. Can you use recursive functions ?
0
 
windshireAuthor Commented:
recursive has not been covered in class ;( so that is out as well

all these restrictions of only being able to use what was taught is driving me nuts

no array type for strings. heck if i could use a general array would store the number and convert it to a char but not even allowed to do that.
i am in a total brainpop mode
no strings other than  cout <<"blah blah"

just basic for, while, if loops/statments

i am trying to NOT have to do it the following manner
#include<iostream>
 
using std::cin;
using std::cout;
 
int main()
{
	char answer, letterOne=0, letterTwo=0, letterThree=0, letterFour=0, letterFive=0;
	
	int number=0, count=0;
	
	
	cout << "\nWord Finder. User will enter a Letter then a number."
		 << "\nWord finder will move through the alphabet to the ."
		 << "\nnext letter by a count of the number you entered."
		 << "\nAsking User if the combination is a word or not.\n";
		 
	do{
		cout << "\nEnter a letter. ";
		cin >>  letterOne;
		letterOne=tolower(letterOne);
	  }while (!(letterOne >= 'a' && letterOne <= 'z'));		
	    cout << letterOne;
		
	do{
		cout << "\nEnter a number From 1 to 26.\n";
		cin >> number;
	}while (!(number >=0 && number <=26));
		cout << number;
		
	letterTwo=letterOne+number;
	
	cout << "\nIS \""<< letterOne << " " << letterTwo << "\" a word? y for yes. n for no ";
	cin >> answer;
	answer=tolower(answer);
	{
		if (answer='n')
		{
			letterThree=letterTwo+number;
			cout << "\nIS \""<< letterOne << letterTwo << " " << letterThree <<"\" a word? y for yes. n for no ";
			cin >> answer;
			answer=tolower(answer);
		}	
	
			if (answer='n')
			{
				letterFour=letterThree+number;
				cout << "\nIS \""<< letterOne << letterTwo << letterThree << " " << letterFour <<"\" a word? y for yes. n for no ";
				cin >> answer;
				answer=tolower(answer);
			}	
			
			
					if (answer='n')
					{
						letterFive=letterFour+number;
						cout << "\nIS \""<< letterOne << letterTwo << letterThree << letterFour << " " << letterFive <<"\" a word? y for yes. n for no ";
						cin >> answer;
						answer=tolower(answer);
					}	
		else
				cout << "\nYou found a word";
	}		
		
		
   
 
	if (count <10)
		cout << "\nFound a Word in "<< count<<" trys.";	
		
		else
			cout << "\nNo Words Found!!";
		
	return 0;
}	

Open in new window

0
 
windshireAuthor Commented:
i am trying to verify. no luck so far.
unfortunatly im one of those people that refuse to stop something until i find a solution or a solution base.

very bad trait when you have other things that need to be addressed. cant stop thinking how to fix this ddarn thing

oh, /im a dorknob --thanks for the operator correction
0
 
windshireAuthor Commented:
ya i am trying like heck to not use the multitude of if/else and 26 variables one for each possible combinations (

i just feel like he is not looking for that. Though I am going to do one just for shiets and giggles so ill have one working 100% properly though poorly coded
0
 
windshireAuthor Commented:
ok all those resrtictions were correct. but got a pointer from instructor on how to do it within boundries

i feel like an idiot now

It's a good question.

Print the same variable over and over again, after updating it each time.

For example:

char letter = 'a';
while ( letter <= 'z' )
{
     cout << letter;
     letter += 1;
}

will print the letters 'a' through 'z'

cant believe i could not figure this out. oh well sometimes something simple bites one in the arse

will award points for your quick responce and efforts
0
 
Infinity08Commented:
>> will print the letters 'a' through 'z'

Yes, but I thought you needed to keep the state of the previous letters, and ask the user's confirmation for each letter ? In that case, this won't work.


Can you post the exact text of the assignment (as I asked earlier) ?
0
 
windshireAuthor Commented:
ok here is how i have that to work

letter = the original letter inputed
number= orignal number input for how many letters over from the original letter it will move
new_letter = letter + number
the below code is placed inside a for loop adding ++cycle everytime the combined letters is not a word

so the while loop will output one additional letter at an interval of number

so if cycle was set a 1 (from the ++cycle in the for loop this is inside of) and letter was 'a' and number was 2

will print
a

cycle set at 2
will print
ac

cycle set to 3
ace

etc
so i was on the mindset i needed to store the letter but what ended up needing is to have it go through adding another character each time we said it was not a word
	while (new_letter <= 122 && count <= cycle )//122 is ascii z
	{
		cout << letter ;
		letter+=number;
		++count;
	}

Open in new window

0
 
windshireAuthor Commented:
sorry in advance am new to c++, 2 weeks, so new i dont even know how to properly ask a question about it

Thanks a ton for your help
0
 
Infinity08Commented:
No problem. I apparently completely misunderstood what you wanted to do :) So you don't really need the user's confirmation then, like :

        cout << "\nIS "<< letter << new_letter << " a word? y for yes. n for no ";


btw :

>>         while (new_letter <= 122 && count <= cycle )//122 is ascii z

Why not make things a bit more clear, and use 'z' instead of 122 ?

        while (new_letter <= 'z' && count <= cycle )
0
 
windshireAuthor Commented:
still need to output to look like
Is  "ac e" a word? y for yes, n for no

if the number + letter is greater than 'z' (122) need it to not print any other character but lowercase letters

so if letter 'a' (97) and number = 10
the 3rd cycle through it will = 127 and print the extended ascii character
 with useing the number i can simply  new_letter > 122  new_letter = new_letter-26 to start it over from the begining. will print the letter long as i keep it a char

not sure if this is the best way to do it but im new and dont really know how to code effeciently

0
 
Infinity08Commented:
Take a look at the modulo operator (%). It returns the remainder after division. More specifically value % 26 will always be a value between 0 and 25 (inclusive).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.