i need help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
using namespace std;

int main()

{

	  int i;
	  int num;


	  cout <<"Give a value of n: " << endl;
	 cin >> num;

	 while(num>0)
		 
	 {
	 
		   for(i=0;  i+1; i++)

			cout << "o";
	 }

	   
	 {

		  for(i=0;  i+0; i++)

		     cout << "^";
		 }
		cout << "Enter a value" ;
		cin >> num;
		cout << endl;

		system ("pause");

		return 0;

}


Hello i need help for this problem i don’t know what is wrong i tried to solve them and it doesn't come out the solution !

The program should ask the user to enter the value of n, and then print out what is shown
above. The program should repeat this procedure as long the user enters non-negative values.

If n is 4
ooooO
^^^^
If n is 10
ooooooooooO
^^^^^^^^^^
Last edited on
for(i=0; i+1; i++)
What are you trying to do with this?
I didn't get the chance to test this, just wrote it based on your example.
Check if it works

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{

	int num;
	int temp;

	cout<<"Enter a positive value\n";
	cin>> num;
    
	temp=num;

	for(int i=1; i<(num+1); i++)
	{
		cout<<"o";
	}
		cout<<endl;

	for(int j =1; j <(temp +1); j++)
	{
		cout<<"^";
	}	
	
return 0;

}
nic, your while loop will never end. Nothing in that loop changes the value of num. If it is greater than 0, then it will enter the loop and will loop infinitely, as it will stay greater than 0 for ever.

For that matter, your for loop will never be entered. You've put i+0 as your loop check condition. Since you initialise i to 0, the first time this is checked, i+0 will be 0 + 0 = 0, i.e. false. The loop will therefore immediately exit.

What are you trying to achieve with your while loop?

What are you trying to achieve with your for loop?
Topic archived. No new replies allowed.