13:16 [Warning] character constant too long for its type (NOT AN ISSUE!)
In function `int main()':
15 expected primary-expression before "else"
15 `;' before "else"
This is my script:
#include <iostream>
using namespace std;
int main (){
char stop = 0;
int n;
cout << "Enter the starting number > " << endl;
cin >> n;
while (n>0){
cout << n << ", " << endl;
cin >> stop;
if (stop = 'abort'){
break;
else{
continue;
}
}
Thanks, that got rid of the errors. I can see that what you've done was was including the string library and changed the char into a string as a string can hold more data then a char and in line 1.4 you added an extra = (not sure what the difference is). However, the main point of the program was to make it count down to 0, hitting the 0 making the program end. I know that it doesn't count down because of the break; operation but I can't see how can that affect the program if I don't make stop == abort. I read something about it, I guess I'll go on investigating and while writing this I found out how to make it count down. Altogether, I thank you very much for your help, I used it to rewrite my code properly :)
//this block's syntax is incorrect.
if (stop = 'abort'){
break;
else{
continue;
}
}
//The proper SYNTAX (and not code) will be
if (stop = 'abort'){
break;
} //Inserted an bracket!!
else{
continue;
}
I maintain that people do write C++ code. The only people who sit down to write C++ syntax is the ISO language definition group. Syntax concerns grammar; it is the rules of a given language or notation. C++ code has rules, but C++ code is not those rules.
if (stop = 'abort')
That's incorrect. The ' notation goes around a single character. Putting it around a multi-character string is bgad. Perhaps you meant if (stop = "abort"')
@Moschops
Sorry if you got me wrong!! I was ONLY trying to tell the OP about the structure of an if-else block and I ignored other details because I assumed that the OP will be overwhelmed to see all those details at once.
That's OK! :) I managed to do some research and got the loop to work and pretty much everything. EXCEPT for one thing. This is, finding a way where the user can input something within a limited time and not until the user inputs something. By this I mean that something like: cin >> abort;
will not work as it wont continue until the user inputs something.
So, to summarize, is there a way to giving the user a certain time-limit within which he has to input something or the program will continue?