4 Replies - 1186 Views - Last Post: 30 October 2011 - 01:51 PM Rate Topic: -----

#1 hforte   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-October 11

Beginner C++ End of Data Nesting Loop Help

Posted 30 October 2011 - 09:34 AM

I am trying to write a program to input two integers so that several sets of data
can be processed...having trouble nesting within statements.
#include <iostream>
using namespace std;
int main()
{
		//variable declarations
	int a = 0;
	int b = 0;
	int	set_no = 0;

		//prompt user for integers
	cout << "\nEnter Set number ==>";
	cin  >> set_no; 
	cout << "Please enter value for Integer A and press the Enter key ;";
	cin >> a;
	cout << "Please enter value for Integer B and press the Enter key ;";
	cin >> b;

	while (!(set_no == -999))
	{
			//decide whether Integer A is larger than Integer B
		if (a > B)/>
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is larger than Integer B ";
			cout <<b;
			cout <<"\n";
		}
		else
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is not larger than Integer B ";
			cout <<b;
			cout <<"\n";

		}//end if

	
		cout << "\nEnter Set number ==>";
		cin  >> set_no; 
		cout << "Please enter value for Integer A and press the Enter key ;";
		cin >> a;
		cout << "Please enter value for Integer B and press the Enter key ;";
		cin >> b;

	}//end while


	cout << "\n   End of Program\n";


				//Add lines for Visual Studio 2010
	int xx;
	cout << "\nPress any key to continue, then hit the Enter key!";
	cin >> xx;

	return 0;

}//end of program



This post has been edited by Salem_c: 30 October 2011 - 10:30 AM
Reason for edit:: move prose outside the code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Beginner C++ End of Data Nesting Loop Help

#2 tonydav43   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 51
  • Joined: 21-October 11

Re: Beginner C++ End of Data Nesting Loop Help

Posted 30 October 2011 - 10:55 AM

View Posthforte, on 30 October 2011 - 09:34 AM, said:

I am trying to write a program to input two integers so that several sets of data
can be processed...having trouble nesting within statements.
#include <iostream>
using namespace std;
int main()
{
		//variable declarations
	int a = 0;
	int b = 0;
	int	set_no = 0;

		//prompt user for integers
	cout << "\nEnter Set number ==>";
	cin  >> set_no; 
	cout << "Please enter value for Integer A and press the Enter key ;";
	cin >> a;
	cout << "Please enter value for Integer B and press the Enter key ;";
	cin >> b;

	while (!(set_no == -999))
	{
			//decide whether Integer A is larger than Integer B
		if (a > B)/>
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is larger than Integer B ";
			cout <<b;
			cout <<"\n";
		}
		else
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is not larger than Integer B ";
			cout <<b;
			cout <<"\n";

		}//end if

	
		cout << "\nEnter Set number ==>";
		cin  >> set_no; 
		cout << "Please enter value for Integer A and press the Enter key ;";
		cin >> a;
		cout << "Please enter value for Integer B and press the Enter key ;";
		cin >> b;

	}//end while


	cout << "\n   End of Program\n";


				//Add lines for Visual Studio 2010
	int xx;
	cout << "\nPress any key to continue, then hit the Enter key!";
	cin >> xx;

	return 0;

}//end of program





look here


if (a > B)


but you have declared it as b in the start

b is not the same as B

View Posttonydav43, on 30 October 2011 - 10:51 AM, said:

View Posthforte, on 30 October 2011 - 09:34 AM, said:

I am trying to write a program to input two integers so that several sets of data
can be processed...having trouble nesting within statements.
#include <iostream>
using namespace std;
int main()
{
		//variable declarations
	int a = 0;
	int b = 0;
	int	set_no = 0;

		//prompt user for integers
	cout << "\nEnter Set number ==>";
	cin  >> set_no; 
	cout << "Please enter value for Integer A and press the Enter key ;";
	cin >> a;
	cout << "Please enter value for Integer B and press the Enter key ;";
	cin >> b;

	while (!(set_no == -999))
	{
			//decide whether Integer A is larger than Integer B
		if (a > B)/>
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is larger than Integer B ";
			cout <<b;
			cout <<"\n";
		}
		else
		{	cout << "Integer A ";
			cout <<a;
			cout <<" is not larger than Integer B ";
			cout <<b;
			cout <<"\n";

		}//end if

	
		cout << "\nEnter Set number ==>";
		cin  >> set_no; 
		cout << "Please enter value for Integer A and press the Enter key ;";
		cin >> a;
		cout << "Please enter value for Integer B and press the Enter key ;";
		cin >> b;

	}//end while


	cout << "\n   End of Program\n";


				//Add lines for Visual Studio 2010
	int xx;
	cout << "\nPress any key to continue, then hit the Enter key!";
	cin >> xx;

	return 0;

}//end of program





look here


if (a > B)


but you have declared it as b in the start

b is not the same as B

sorry smiley came in there and cannot stop it

I meant to say look here

on line 7 you declare b = 0 ;

but then on line 21 you capitalise the b
Was This Post Helpful? 0
  • +
  • -

#3 sk1v3r   User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Beginner C++ End of Data Nesting Loop Help

Posted 30 October 2011 - 11:47 AM

Actally, I believe that that is a problem with the website, b's get capitalized on occasion.

Also, you say that you are having problems, but could you name them specifically please :)

Also, some nice shortcuts that can make your code simpler
!(a == B)/>
// is the same as
(a != B)/>

// and another good thing
cout << "one " << one << endl;
// is the same as
cout << "one ";
cout << one;
cout << endl;
// the << operator can be used like this to save lines.


Was This Post Helpful? 0
  • +
  • -

#4 hforte   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-October 11

Re: Beginner C++ End of Data Nesting Loop Help

Posted 30 October 2011 - 12:53 PM

Thanks but the problem is with the while and if/else loops....trying to get a prompt to handle multiple data sets...
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: Beginner C++ End of Data Nesting Loop Help

Posted 30 October 2011 - 01:51 PM

I would suggest that you look into using arrays to hold your "sets".

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1