write a c or c++ or java program for cave exploration?
Answers
Answered by
0
=>-1down votefavorite
Use while loop to print series of even and odd numbers
c++
I know I'm missing something real simple but I can't seem to get the numbers to print out in rows of just odd or just even numbers using a while loop or loops. Also It keeps printing out "the even numbers are:"/ "the odd numbers are:" for every number.
#include<stdio.h> #include <iostream> using namespace std; int main() { //declare variables int number; int n; cout << "Enter value less than 100: "; cin >> n; //take user input while (n <= 100) //loop only if n equals 100 or less { for(number = n; number <= n; number++) //for loop to increment int value { if(number % 2 !=0) //determines if odd { cout << "The odd numbers are:" <<number << endl; //prints odd values } } for(number = n;number <= n; number++) // for loop to increment int value { if(number % 2 ==0) //determines if even { cout <<"The even numbers are:" <<number <<endl; //prints even values } } n++; } return 0; //end of program }
Similar questions
English,
7 months ago
English,
7 months ago
History,
7 months ago
Psychology,
1 year ago
Math,
1 year ago