Answer to Question #8728 in C++ for Faris Al-Raqqad

Question #8728
Write a program that uses while loop that prompts the user to input two integers x, and y. Then output all odd numbers between x and y.
1
Expert's answer
2012-04-26T07:37:25-0400
#include <iostream>
using namespace std;

int main() {
char
answer = 'y';
int x;
int y;
while (answer != 'n') {
cout << "x
= ";
cin >> x;
cout << "y = ";
cin >> y;
if (x
> y) {
int c = x;
x = y;
y = c;
}
cout << "Odd number
between x and y: ";
for (int i = x + 1; i < y; i++)
if (i % 2 !=
0)
cout << i << " ";
cout << endl;
cout <<
"Once more?(y/n) ";
cin >> answer;
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS