Hi... I want to ask smthng about a program Im working on now.. I don't know a lot on C++ and I'm now trying to finish an exercise for my university.
So, I want a program which: starts and displays "1>" and next to this, the user could start typing whatever wants. When the user presses Enter, the program change line and continues counting.. I mean smthng like this:
1> example example
2> example
3> example example
....
and when the user wants to exit, he has to write ":q".
hmm as u can see I'm not so good at this, and the compiler gives me many errors, as you will see this too.
Does anyone have an idea of what I'm doing now????? THANKS!!
99% of your errors should be incredibly obvious from what the compiler tells you.
How about, instead of me just fixing it up for you, you post all of the errors you get and we'll work through them all until you can solve it yourself. This way you've learned something in the end.
1) at line 9: expected init-declarator before "int"
2)at line 9: expected `,' or `;' before "int"
3) at line 11: expected unqualified-id before "do"
4)at line 11: expected `,' or `;' before "do"
5) at line 16:expected unqualified-id before "if"
6) at line 16:expected `,' or `;' before "if"
Error #2 expects a comma or semicolon before your first line in main. Well, this happens when you forget a semicolon at the end of a line of code. It's trying to treat int main(int argc, char *argv[]) as a function prototype, instead of the function itself, because you didn't put the content of that function inside brackets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main(int argc, char *argv[])
{ // <<-- the start of main
int i = 1;
do {
cout << i << ">" << cin;
i++;
while cin =! ":q" }
if cin == ":q" {
system("PAUSE");
return EXIT_SUCCESS;
}
} // <<-- the end of main. You didn't include those two brackets.
Doing that will solve the list of errors right now, but a whole new set will pop up.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
int i = 1;
do {
cout << i << ">" << cin;
i++;
while (cin =! ":q" ); }
if (cin == ":q" ); {
system("PAUSE");
return EXIT_SUCCESS;
}
}
and the errors:
1) In function `int main(int, char**)': 2) line 15: no match for 'operator=' in 'std::cin = 0u' 3) line 17: expected `while' before '(' token 4) line 17: no match for 'operator==' in 'std::cin == ":q"'
Error 2) On line 13, i'm not sure what you're trying to accomplish by outputting the istream.
Error 3) The bracket at the end of line 16 should be before 'while'.
Error 4) You've got your comparing operator wrong. '=!' should be '!='.
You should really read some more on basic C++ syntax/semantics.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main(int argc, char *argv[])
{
int i = 1;
do {
cout << i << ">" << cin ;
i++;
}
while (cin != ":q" );
if (cin == ":q" ); {
system("PAUSE");
return EXIT_SUCCESS;
}
}
but apart from the errors, I want when the user presses enter, the counter (i) continues counting and the user can continues writing at the next line. I think this is gonna happened in do-while but I dont know how.
The errors are: 1) line 16: no match for 'operator!=' in 'std::cin != ":q"' 2) line 18: no match for 'operator==' in 'std::cin == ":q"'
And what about cin?? I have to have it as string or smthg else??