okay, 'm taking a class in basic C++ (yes, I'm a computer noob) and my wonderful teacher teaches us how to do things right, but not how to fix things when they go wrong!
In other words, I'm not sure what the compiler means when it gives me syntax errors.
For the same reason, computer programers' forums confuse me because they are talking about processes I don't understand
that said the exercise I'm doing looks like this:
[spoiler]
An interesting problem in number theory is sometimes called the “necklace problem.” This
problem begins with two single-digit numbers. The next number is obtained by adding the
first two numbers together and saving only the ones-digit. This process is repeated until the
“necklace” closes by returning to the original two numbers. For example, if the starting numbers
are 1 and 8, twelve steps are required to close the “necklace"
Write a program that asks the user for two starting numbers, and then displays
the sequence and the number of steps taken. The program output should look
similar to:
Enter first number: 1
Enter second number: 8
1 8 9 7 6 3 9 2 1 3 4 7 1 8
Your numbers required 12 steps.
[/spoiler]
I'm trying to do this with a for loop, which I'm not even sure is possible, but here's my code if it helps (don't laugh please, I told you I have NO CLUE what I'm doing)
[spoiler]#include<iostream>
using namespace std;
int main ()
{
int result1, result2, num1, num2, count;
cout<<"Enter first number ";
cin>>num1;
cout<<"Enter second number ";
cin>>num2;
cout<<num1<<" "<<num2<<" ";
for(result1=(num1+num2)%10;(result1==num1)&&(result2==num2);result1=(result2+num2)%10;)
{
cout<<result1<<" ";
result2=(result1+num2)%10;
cout<<result2<<" ";
count++;
}
cout<<"Your numbers required "<<count<<" steps."<<endl;
system ( "Pause" );
return(0);
}
[/spoiler]
I get three errors, all in the line containing my fail for loop
"expected ) token before ;
expected ; token before
expected primary-expression before ) token"
Which I'm assuming is telling me I need () and ; but I can't figure out why...
The other thing this tells me is I'm doing this completely wrong and need a do while loop. Does anybody else know?
Thanks, and PLEASE don't tell me how to fix logic errors in my program. I'm aware this probably won't work on the first run, but I want to make it work on my own. I just need help with the syntax. Thanks.
EDIT: I no longer have errors because I rewrote the code because I discovered logic problems, but I still would like to know what was wrong with the syntax