1. ## BADLY NEED HELP MASTERS. Thanks!

Here is my problem, I can't figure out this simple tasking job. here it is

Problem #1
Ask the user for a number(1-5), say X. Check for input validity. In cases of an invalid input, continuously ask the user to enter a number until he finally enters a valid one. Print the numbers from1 to X for each row starting from row 1 to row X. (It is required to use looping constructs)

sample run:
Enter a number (1-5):0
0 is an invalid entry. Try another.

Enter a number (1-5): 3

row 1: 1 2 3
row 2: 1 2 3
row 3: 1 2 3

here's my problematic code for that problem:
Code:
```#include<stdio.h>

int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
}	while ((num<1)||(num>5));
for(int i=0; i<1; i++){
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}
return 0;
}```
PROBLEM 2:

write a program that continually asks the user to enter an integer until he/she enters the number 0. Display the maximum of these numbers and the number of times it appeared.

Sample run:

Enter a number: 2

Enter a number: 3

Enter a number: 5

Enter a number: 1

Enter a number: 8

Enter a number: 8

The largest number is 8 and it was entered 2 time(s).

here is my sample problematic program

Code:
```#include<stdio.h>

int main(void)
{

int a, i, m, j, n;

printf("enter a number: ");
scanf("%d", &number1);
max=count+1;
count=1;

void largest(int a[][MAXCOLS],int m,int n)
{
int i,j,largest;
largest = a[0][0];
for (i=0;i<m;++i)
{
for (j=0;j<n;++j)
{
if (a[i][j]>largest)
largest=a[i][j];
}
}
printf("
The largest element of the matrix is %d",largest);
printf("\n\nThe largest number is %d and it appeared %d time(s).", max, count);

return 0;
}```
by noobprogrammer

2. Code:
```			for(int i=0; i<1; i++){
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}```
look at your limits for the for loops...shouldn't they have something to do with num?

Don't know what you're doing for #2...it should be much shorter than that. All you need to do is keep asking until the input is 0, otherwise the only other thing that should be going on is:
if the last input is bigger than the largest, set the largest to the last input and reset the number of times the largest has been counted (or increment if you want to keep track, might want to use an array). otherwise, if the input matches the largest, then increment the number of times it's been entered.

3. sufoode, that's using C++, not C, and you shouldn't do his homework for him/her, that's not letting him/her learn.

Besides, void main doesn't follow the standard, they should be int mains, <stupid mistake>and your solution to #2 doesn't correctly count how many times a number has been entered. What if the user entered 5 5 5 1 5? Your program would say that 5 has been entered once.</stupid mistake>

4. Hell, I went and confused myself. You're right.

Still, don't do homework for people, and this particular forum section is for C, not C++.

5. wow, thanks for replies, maybe the C++ can't help me we are doing it in C our professor forbids using c++ anyway thanks i'll ask you some more questions as i go through your answers and understand it. Thanks by the way. for your replies ^_^

6. I forgot in problem number two after entering 0 the screen will print the largest number and its recurrence in the whole program. Thanks for your help again masters!

7. Code:
```	for(int i=0; i<1; i++){
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}```
Wah! what should I do with the loops? Can someone with a good heart explain to me this please because honestly our professor's mouth is racing with the spped of light. Totally, I'm a beginner in programming.

8. Just put some thought into it!!!! Don't be such a lazy twit.
Code:
```for(int i=0; i<1; i++){ // How many times will this be executed if i starts at 0 and must be < 1?
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){ // How many times will this be executed if j starts at 0 and must be < 0???
printf("%d", j+1);
}
}```

9. Code:
```	#include<stdio.h>

int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
}	while ((num<1)||(num>5));

for(int i=1; i<=num; i++){
printf("\nrow %d:", i);
}
return 0;
}

===========

#include<stdio.h>

int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
}	while ((num<1)||(num>5));
for(int i=0; i<num; i++){
printf("\nrow %d: ", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}
return 0;
}```
Masters, I've tried this code but all that appears is for example:

row 1:
row 2:
row 3:

what I need is

row 1: 123
row 2: 123
row 3: 123

Can anyone pinpoint the mistakes in my program? thank you in advance.

10. thanks for the answers, I'm really sorry because I really didn't understand this thing completely.

11. Code:
```for(int i=0; i<1; i++){ // How many times will this be executed if i starts at 0 and must be < 1?
printf("\nrow%d", i+1);
for(int j=0; j<0; j--){ // How many times will this be executed if j starts at 0 and must be < 0???
printf("%d", j+1);
}
}```
Am I right the first one will be executed at exactly one time only? while the 2nd one will not be executed. That's wrong in'st it?

12. Masters! Thanks for your words of wisdoms and sermons, i've solved the 1st problem, the 2nd one is the only problem. Yahoo!

13. Code:
```	#include<stdio.h>

int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
}	while ((num<1)||(num>5));

for(int i=1; i<=num; i++){
printf("\nrow %d:", i);
}
return 0;
}

===========

#include<stdio.h>

int main (void)
{ int num;
do {
printf("Enter a number (1-5):");
scanf("%d", &num);
if((num<1)||(num>5))
printf("%d is an invalid entry. Please enter another one.\n", num);
}	while ((num<1)||(num>5));
for(int i=0; i<num; i++){
printf("\nrow %d: ", i+1);
for(int j=0; j<0; j--){
printf("%d", j+1);
}
}
return 0;
}```
Masters, I've tried this code but all that appears is for example:

row 1:
row 2:
row 3:

what I need is

row 1: 123
row 2: 123
row 3: 123

Can anyone pinpoint the mistakes in my program? thank you in advance.

14. Look again at this for-loop:

Code:
`for(int j=0; j<0; j--){`
How many times will the loop be executed?
Think about how you could rewrite this to make it work.