954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Odd numbers in C++?

Ja-ja I'm new to this c++, BUT egger to learn. I want to write a program that will cout all the odd numbers between 6 and a positive integer.It must also be bigger than 53. This is what I came up so far but it doesn't give any output :

cout<<"Please enter a number not less than 53\n";
int a, i; // Declare the number input
cin>>i;
while (i <= 53)
{ cout << "No, bigger than 53! Try again : ";
cin >> i;
for (a>6;a<=i;a++); //Execution of the series
if (a%2!=0); // calculating the odd numbers
cout << a <

Jobe007
Newbie Poster
2 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
for ( int c = 7; c < i; c += 2)
    cout << c << "\n";
Sturm
Veteran Poster
1,079 posts since Jan 2007
Reputation Points: 343
Solved Threads: 24
 

> for (a>6;a<=i;a++); //Execution of the series
> if (a%2!=0); // calculating the odd numbers
The trailing ; on both these lines is a huge problem.

Next time, use [code][/code] tags around your code.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Here is the improoved version
#include
void main(){
int n;
do
{
cout<<"\Enter a Value bigger than 53: ";
cin>>n;
}while(n>53);

for(int i=7,j=0;i

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

void main is not an improvement, and nor is posting code without using [code][/code] tags.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Nice for loop

I believe the proper format is
for(int a = x ; a < y; a++)

pacman326@gmail
Light Poster
43 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

Salem's request is to repost your code with formatting and Code Tags ... When we can read the code, we can help.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You