May 10, 2011 at 10:06pm UTC
Elo, need some help.
#include <iostream>
using namespace std;
void print();
int main(){
int x;
cout << "Hello, enter the number 5";
cin >> x;
if(x == 5){
cout << "Nice!" << endl;
}
else
print();
return 0;
}
void print(){
int y;
cin >> y;
while (y > 0){
cout << y << endl;
y++;
}
}
Just run the project. Why after you type in the wrong answer (Not 5) That you have to type in another number to activate the loop?
Thx lots!
(This program is of no help, and im just seeing how stuff works)
May 10, 2011 at 10:18pm UTC
Because inside the function before the loop you ask for input.
May 11, 2011 at 1:13am UTC
Uhh?
Sorry, what/which function are u talking about? (totally new at this lmao)
;
May 11, 2011 at 1:39am UTC
It's the print() function. If you put the code in [co de][/code] tags, I could give a line number.
May 11, 2011 at 1:47am UTC
And i had void print();
I thought it makes it go first?
May 11, 2011 at 1:54am UTC
? No, the main() function is always run when the program starts, and other functions are run only if you call them. On line 17, you call the print() function. You asked why it waited for input; that's because on line 29 you ask for input before running the loop.
May 11, 2011 at 3:13am UTC
Zhuge: So what do i have to change??? W/o cin >> y; it does not work.
Firedraco: If you look at my first post, you see i said "This program is not help, just wanting to see how things work. :)
May 11, 2011 at 3:25am UTC
What is it supposed to do?
May 11, 2011 at 7:12pm UTC
Like if you get it wrong (Not == to 5) it randomly turns on the loop. If you do get it right, it does nothing.
Last edited on May 11, 2011 at 7:33pm UTC