Would anyone be able to help me with this assignment. I pretty much almost got it, but I'm still stuck. Here is the assignment:

Write a program that asks the user for two integers; call
them num1 and num2. Make sure the number is between 1 and 9
(including 1 and 9). For each pair of numbers, print the
division of those two numbers. Note that this is integer
division, so there will be no fractional parts.
See the examples below.

EXAMPLE 1:
Please enter a number between 1 and 9: 3
Please enter another number between 1 and 9: 2
1 0
2 1
3 1

EXAMPLE 2:

Please enter a number between 1 and 9: 9
Please enter another number between 1 and 9: 9
1 0 0 0 0 0 0 0 0
2 1 0 0 0 0 0 0 0
3 1 1 0 0 0 0 0 0
4 2 1 1 0 0 0 0 0
5 2 1 1 1 0 0 0 0
6 3 2 1 1 1 0 0 0
7 3 2 1 1 1 1 0 0
8 4 2 2 1 1 1 1 0
9 4 3 2 1 1 1 1 1
Press any key to continue . . .

EXAMPLE 3:
Please enter a number between 1 and 9: 10
That number is out of range.
Press any key to continue . . .

Here is the code I have below. All is does right now is just continues to ask me to enter a number and doesn't do anything else. What do I need to change?

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int howmany = 0;
	int num1, num2;
	do
	{
		cout << "Please enter a number between 1 and 9: ";
		cin >> num1;
		cout << "Please enter another number between 1 and 9: ";
		cin >> num2;
		
		if ((num1 >=1) && (num1 <=9) || (num2 >=1) && (num2 <=9))
		{
			for (int num1 = 1; num1 = howmany; num1--)
			{
				for (int num2 = 1; num2 = howmany; num2--)
				{
					cout << num1/num2 << '\t';
				}
				cout << endl;
			}
		}
		else
		{
			cout << "That number is out of range. " << endl;
			break;
		}
	}
	
	while ((num1 >= 1) && (num1 <=9) || (num2 >=1) && (num2 <= 9));
	return (0);
}

Recommended Answers

All 7 Replies

The use of num1 and num2 in lines 17 and 22 is destroying the values you entered on line 13 and 15. Use some other variables on lines 17 and 22

for (int num3 = 1; num1 <= num1; num3++)
{
       for (int num4 = 1; num4 <= num2; num4++)
       {
           cout << num3/num4 << '\t';
       }
}

Ignore the first coding that I put up b/c I figured out how to get the error message up for this assignment...aka...the "that number is out of range" part. However, here is the new code below and I can't get the result to print out and just wondered what else I have to do. I will keep working on it, but someone please help. Thanks :) .

include <iostream>
#include <string>

using namespace std;

int main()
{
	int howmany = 0;
	intnum1, num2;

	cout << "Please enter a number between 1 and 9: ";
	cin >> num1;
	if ((num1 >= 1) && (num1 <= 9)) 
	{
		cout << "Please enter another number between 1 and 9: ";
		cin >> num2;
		if ((num2 >= 1) && (num2 <= 9))
		{
			for (int num1 = 1; num1 = howmany; num1--)
			{
				for (int num2 = 1; num2 = howmany; num2--)
				{
					cout << num1 / num2 << '\t';
				}
				cout << endl;
			}
		}
	}
	else[/COLOR} 
	{
		cout << "That number is out of range. " << endl;
	}
}

Its impossible to read that code because of all the color tags you inserted. Did you bother to read my previous post ??? (I'll bet you didn't)

yes i did. i just changed it around. im sorry that i have another question. I won't post anymore if this is how you are going to respond. I'm sorry, but I find it rather rude the way you responded!!!

>>yes i did.
Than I guess you just ignored it because you didn't change a thing about those loops. I'm not going to try to answer your questions if you just ignore everyone's suggestions.

Repost without all those color tags and use code tags to make it readable.

Here is the repost. Sorry it doesn't have any color to it, but I haven't figured out how to do that yet. But here is the redone code. I got it pretty much to work except for it keeps going and going...lol. I know I have to insert a break or return somewhere, just not sure where.

Here is the code:

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int num1, num2;

	cout << "Please enter a number between 1 and 9: ";
	cin >> num1;
	if ((num1 >= 1) && (num1 <= 9)) 
	{
		cout << "Please enter another number between 1 and 9: ";
		cin >> num2;
		if ((num2 >= 1) && (num2 <= 9))
		{
			for (int num1 = 1; num1 <= num1; num1++)
			{
				for (int num2 = 1; num2 <= num2; num2++)
				{
					cout << num1 / num2 << '\t';
				}
				
			}
			cout << endl;
		}
	}
	else 
	{
		cout << "That number is out of range. " << endl;
	}
}

Again, sorry it doesn't have any color, but I haven't had a chance to learn how to use that yet.

>>Again, sorry it doesn't have any color, but I haven't had a chance to learn how to use that yet

Read your PMs. You have a PM that shows you how to do that. Scroll up to the very top of the page and click the PRIVATE MESSAGES link.

And re-read the code in my original post here. What you implemented is totally wrong. Paying attention to detail is required in programming.

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.