It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I´ve programmed a random writing program. That uses the markov algorithm. So it selects a order of letters, say [th] then go finding what appears most frequent after that using some randomness etc. But if the program selects a letter that has no "siblings". for example say right at the end of the file this symbol is [%] and it do not appear anywhere else in the file. What happens then is that the program just says "Finished running" it don´t even execute the coutcommand that prints out the string newText.
Why is this?
The rest of the code does basically some manipulation of arrays (adding etc..), to much code to post here.
for (int i = 0; i < fullText.length(); i++)
{
newText += getNext(currentWord, curWordPos, order);
}
cout << "Output: " << newText << endl;
Is this an Infinite loop?
No, it's not.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have an existing program written in c++ that counts the number of words. How would I go about converting this to assembly to run on something like the 68000 processor? Where should I start?
int _tmain(int argc, _TCHAR* argv[])
{
int i=0;
int words=0;
bool last_space=true;
while( test_string[i]!=0)
{
if(!last_space && test_string[i]==' ')//end of word - space preceded by not space must handle multi spaces
words=words+1;
if (test_string[i]==' ')
last_space=true;
else
last_space=false;
i++;
}
return 0;
}
A few hints as this seems to be some typical homework assignment:
You have to loop until a certain condition is fullfilled. So you should look up your assmebly instruction book and find commands where you can read a byte from memory compare it, branch and jmp instructions.
I would start with a simple loop and when you know how to do this, add the next conditions, checking for spaces and so on.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm new to C++ programming. I want to know how I can input any numbers such as 1256 or 2523 and have the output read as 12.56 or 25.23?
Basically what I want is for the last two digits to appear on the right side of the decimal.
float value = input / 100.0f;
// C way
printf("%.2f\n", value);
// C++ way
cout << setiosflags(ios::fixed) << setprecision(2) << value << endl;
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What is the fastest way(code) to take integer input from user via terminal (not file...:P).
P.S 1: Integers are of small size( within size of int) but the total number of intergers is very large.
P.S 2: Scanf toooo... slow
P.S 3: Forget the human limits ,talk technical...plz
I think an approach based on scanf will be hard to beat. In any case, it will be easy to implement. So I'd start with that, if it's not sufficient, benchmark before trying anything else.
If the input consists of whitespace-separated integers:
scanf("%d ", &input)
for continuous input processing you can try this
while( scanf("%d ", &val) == 1)
{
// processing : do what you want
}
also you can use this for file inputs reading (fscanf)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I know various ways to check if an integer is a palindrome or not by using string conversion, stack and number breaking, but here question is
"How can we check wether an integer is a palindrome or not, without using any extra space?"
You can revert a number with some code like:
int revert(int num) {
int reverted = 0;
while (num) {
reverted = reverted*10 + num%10;
num /= 10;
}
return reverted;
}
And now you only check if
num == revert(num)
That is all. Sorry for giving the exact solution instead of just a tip, but I don't think I could have given any tip without the solution itself.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a loop in C++ that am stuck with, I want to end the loop by entering a blank, if a character is entered then the loop goes on. using VS2010
Presumably you have a variable storing a single character, and are wanting to stop the loop when someone enters a blank character (I'm going to presume space).
Just use a if statement and a break clause
while (true) {
// Get character here and put it into myChar variable
if ( myChar == ' ' )
{
break;
}
}
You could also put the check in the while condition if you have nothing else there. Another alternative would be a do-while loop.