11 Replies - 5624 Views - Last Post: 25 October 2013 - 06:54 AM Rate Topic: -----

#1 Smokey&Ben  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 15-September 13

Infinite Loop or Error "system" is ambiguous

Posted 18 October 2013 - 11:21 AM

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?
//abbb.cpp
#include <iostream>
using namespace std;
int main()
{
	int A,B;
	for (A=1;A=1;A=1)
	{
		cout<<"A"<<A<<endl;
		//}
		for (B=1;B=1;B=1)
			//{
			cout<<"B"<<B<<endl;
		//}
		for (B=2;B=2;B=2)
			//{
			cout<<"B"<<B<<endl;
		//}
		for (B=3;B=3;B=3)
			//{
			cout<<"B"<<B<<endl;
		//}
		for (A=2;A=2;A=2)
			//{
			cout<<"A"<<A<<endl;
		//}
		for (B=1;B=1;B=1)
			//{
			cout<<"B"<<B<<endl;
		//}
		for (B=2;B=2;B=2)
			//{
			cout<<"B"<<B<<endl;
		//}
		for (B=3;B=3;B=3)
			//{
			cout<<"B"<<B<<endl;
	}
	system ("Pause");
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Infinite Loop or Error "system" is ambiguous

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4004
  • View blog
  • Posts: 12,360
  • Joined: 25-December 09

Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 06:38 AM

Quote

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?

Nope, not an infinite loop issue.

There are two ways of fixing your problem with system().

First don't use system() to pause the program. This system() call is very inefficient and not supported by most operating systems. Instead use cin.get() to pause the output.

Second include the proper #include file that prototypes this function. You can use the search engine of your choice to find the documentation for this function, which should tell you what include file is required.


Jim

This post has been edited by jimblumberg: 19 October 2013 - 06:39 AM

Was This Post Helpful? 0
  • +
  • -

#3 axel1994  Icon User is offline

  • D.I.C Head

Reputation: 83
  • View blog
  • Posts: 167
  • Joined: 27-May 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 09:27 AM

View Postjimblumberg, on 19 October 2013 - 01:38 PM, said:

Quote

Error says "system" is ambiguous
It looks like an infinite loop issue
How do I fix it?

Nope, not an infinite loop issue.

There are two ways of fixing your problem with system().

First don't use system() to pause the program. This system() call is very inefficient and not supported by most operating systems. Instead use cin.get() to pause the output.

Second include the proper #include file that prototypes this function. You can use the search engine of your choice to find the documentation for this function, which should tell you what include file is required.


Jim


But:
for (A=1;A=1;A=1)


will give an infinite loop.
At least it does in Visual Studio 2012.

A is initialised to 1.
A gets set to 1. 1 evaluates to true.
A gets set to 1.
A gets set to 1. 1 evaluates to true.
And so on.

(If I'm correct on what happens)

This post has been edited by axel1994: 19 October 2013 - 09:28 AM

Was This Post Helpful? 1
  • +
  • -

#4 salazar  Icon User is offline

  • D.I.C Addict

Reputation: 87
  • View blog
  • Posts: 539
  • Joined: 26-June 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 10:05 AM

Yeah, that is an infinite loop. You should never assign in the conditional section of for loops. You should study some for loops that are written properly.

This post has been edited by salazar: 19 October 2013 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4004
  • View blog
  • Posts: 12,360
  • Joined: 25-December 09

Re: Infinite Loop or Error "system" is ambiguous

Posted 19 October 2013 - 04:58 PM

Quote

will give an infinite loop.

Yes there is an infinite loop. But the OP didn't ask about that, he asked about an error about his system() call, the infinite loop is not the cause of the error that was reported.

Also if the OP used a decent compiler he would get more warning/error messages than what was shown.

Quote

main.cpp||In function ‘int main()’:|
main.cpp|7|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|11|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|15|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|19|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|23|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|27|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|31|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
main.cpp|35|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|


I didn't comment about the rest of the code because that was not the reported problem.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 Smokey&Ben  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 15-September 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 20 October 2013 - 06:24 PM

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy
Second system("Pause")is very efficient and is supported by all of my operating systems
Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

I want it to print using nested loops A1B1B2B3A2B1B2B3
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4004
  • View blog
  • Posts: 12,360
  • Joined: 25-December 09

Re: Infinite Loop or Error "system" is ambiguous

Posted 20 October 2013 - 07:30 PM

Quote

Second system("Pause")is very efficient and is supported by all of my operating systems

No, it's not efficient and relying on system specific functionality when learning a language is also very inefficient. But since you think the only valid operating system is Windows, I'll let someone else address most of your other issues.

Quote

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy

Since it's not running correctly what do you think you should do?

Quote

Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

Then what exactly do you use to get input from the user?

Good luck with your attitude you're really going to need it.

Jim
Was This Post Helpful? 2
  • +
  • -

#8 Smokey&Ben  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 15-September 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 10:10 AM

Okay their other systems than windows but I use Windows and in some cases system("Pause") may not be efficient.
I use cin>> for my programs except with in some cases with strings.
When my program does not run correctly I turn to my peer my student advisors my professor and in some cases my fellow respectable programmers.
I try to help them when I can to in exchange.
Was This Post Helpful? 0
  • +
  • -

#9 Smokey&Ben  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 15-September 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 10:18 AM

Here is the complete code
//abbb.cpp
#include <iostream>
using namespace std;
int main()
{
	int A,B;
	for(A=1;A<2;A++)
	{
		cout<<"A"<<A;
	}
	for(B=1;B<=3;B++)
	{
		cout<<"B"<<B;
	}
	for(A=2;A<3;A++)
	{
		cout<<"A"<<A;
	}
	
	for(B=1;B<=3;B++)
	{
		cout<<"B"<<B;
	}
	system ("Pause");
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3535
  • View blog
  • Posts: 10,943
  • Joined: 05-May 12

Re: Infinite Loop or Error "system" is ambiguous

Posted 21 October 2013 - 09:27 PM

If you are using Visual Studio, there is no need for the system() call. Simply press Ctrl-F5. It will hold the console window open for you.
Was This Post Helpful? 1
  • +
  • -

#11 Smokey&Ben  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 15-September 13

Re: Infinite Loop or Error "system" is ambiguous

Posted 24 October 2013 - 07:42 PM

Thanks Skydiver
Was This Post Helpful? 0
  • +
  • -

#12 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 160
  • View blog
  • Posts: 1,403
  • Joined: 13-June 08

Re: Infinite Loop or Error "system" is ambiguous

Posted 25 October 2013 - 06:54 AM

In case you want to know for future assignments, system is defined in cstdlib. So
#include <cstdlib> //contains system



View PostSmokey&Ben, on 20 October 2013 - 07:24 PM, said:

Okay first to clarify I use Visual Studio 2010.
-as long it runs correctly it is fine is my philosophy


void makeNumber(int *num);
int main(){
  int *a=NULL;
  makeNumber(a);
}
void makeNumber(int *num){
  num = new int;
}


This code runs fine, but it's certainly not 'ok.' It creates a memory leak. Never assume that compiling and running is the same as working.

View PostSmokey&Ben, on 20 October 2013 - 07:24 PM, said:

Second system("Pause")is very efficient and is supported by all of my operating systems


System("Pause") is not efficient in any way. There hasn't really ever been an argument on this point. It's also not a guarantee that it will work. It's the same as typing pause into the command prompt. You're assuming that there is a program in the user's path that is named pause and hoping that there isn't a pause in the current folder. Because if there is, it doesn't work. Windows, for all its bad, does at least one thing correct: It resolves requests locally and moving up rather than starting at the top and moving down.

IT's also a shortcut that doesn't actually teach you programming.

View PostSmokey&Ben, on 20 October 2013 - 07:24 PM, said:

Third I am a student and my professor forbids use getline
-cin.get() I'm not familiar with it at all

cin.get is not getline. Getline is a c++ function that copies a line from a stream up to a \n into a string.
cin.get is a function with several uses which you can read here.

This post has been edited by ccubed: 25 October 2013 - 07:09 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1