#include<iostream>
usingnamespace 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
^^^^^^^^^^
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?