Hello! I've made this simple code, but am not sure where to go from here.
int main()
{
int i;
cin >> i;
for (int i = 1; i < 5; i += 2)
std::cout << i << std::endl;
}
I need to create a program that lets the user input five numbers, and only displays the odd numbers and skips the number 9, and if the number 9 is entered, then the program does not display the number 9 when displaying the odd numbers.
Should I be adding more variables?
// I need to create a program that lets the user input five numbers
for ( int i = 0 ; i < 5 ; i++ ) {
int number;
cin >> number;
cout << "You entered " << number << endl;
}
Then I would edit it to this.
1 2 3 4 5 6 7
// I need to create a program that lets the user input five numbers
for ( int i = 0 ; i < 5 ; i++ ) {
int number;
cin >> number;
// and only displays the odd numbers
cout << "You entered " << number << endl;
}
Now you look at the code, in particular the most recently added comment, and you think about a line of code that determines whether number is odd.
You keep adding one specific step of your requirements until the program is done.
I've done this,
@salem c
int main()
{
for (int i = 0; i < 5; i++) {
int number;
cin >> number;
{
if (number % 2 != 0)
cout << "You entered " << number << endl;
else cout << "Doesn't count. \n";
{
if (i == 9) continue;
}
}
}
}
I feel like I have too many scopes...
I can't get the program to skip the number 9 as well if entered from the keyboard, I feel like I am close though. Is there something I'm missing?