error message is seen on the goto statement. did I miss library ?


this is a part of script.

#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

int main() {
int a = 0, b = 0, c = 0;
cin >> a >> b >> c; //assume error checking etc
start:
if(a > 6) goto a;
else if(b < 2) goto b;
goto 5;
l1:
goto start;

Why are you using goto. It is not a good programming practice to use goto.
You are also not using the proper "goto label". Like

goto a;

and you are not declaring any label with identifier 'a'.

>error message is seen on the goto statement. did I miss library ?
goto is a part of the core language, not a library feature. If you're getting an error, you used it wrong. Looking at your code, you clearly don't understand the concept of goto, so I'd suggest going rereading your book/tutorial/reference.

Anyone hungry for some Spagehetti!?!?!

thank you sundib label identifier is missing.
thisscript is working
#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
int a,b;
cout << "hello";

int i=0;
a:
i++;
if (i>1000)

goto b;
else
{
cout <<i<< "\n";
goto a;
}
b:
getch();
}

OMG I hope he is not taking a college course ;)

A better way to write that. Note that you don't need all those C header files.

#include <string>
int main()
{
   for(int i = 0; i < 1000; i++)
   {
      std::cout << i << '\n';       
   }
   std::cin.get();
   return 0;
}

std::cout << i << '\n';

I compile your program, there is a problem seen on the above statement.
why?

Probably a brain fart. AD should have included <iostream>, not <string>. Here's a more concise way of writing your code:

#include <iostream>

int main()
{
    int i = 0;
loop:
    if (++i > 10)
        goto end;

    std::cout<< i <<'\n';
    goto loop;
end:
    return 0;
}

Though manually building loops like that is borderline stupid in C++. Presumably you're only doing it to learn how goto works.

Thank you Narue.
your program is good example ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.