Odd numbers in C++?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 2
Reputation: Jobe007 is an unknown quantity at this point 
Solved Threads: 0
Jobe007 Jobe007 is offline Offline
Newbie Poster

Odd numbers in C++?

 
0
  #1
Oct 21st, 2007
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 <<endl;
cout <<"This is the odd numbers between 6 and "<<i<<"\n";
cout<<endl;

Can anybody help? I'm sure there must be an easier way of doing this.
<email snipped>
Last edited by Ancient Dragon; Oct 21st, 2007 at 5:49 pm. Reason: email snipped
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,066
Reputation: Sturm is on a distinguished road 
Solved Threads: 24
Sturm's Avatar
Sturm Sturm is offline Offline
Veteran Poster

Re: Odd numbers in C++?

 
0
  #2
Oct 21st, 2007
  1.  
  2. for ( int c = 7; c < i; c += 2)
  3. cout << c << "\n";
"Hey ass, don't hijack my thread. This is serious." -JoshSCH
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Odd numbers in C++?

 
1
  #3
Oct 21st, 2007
> 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 794
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Odd numbers in C++?

 
0
  #4
Oct 21st, 2007
Here is the improoved version
#include<iostream.h>
void main(){
int n;
do
{
cout<<"\Enter a Value bigger than 53: ";
cin>>n;
}while(n>53);

for(int i=7,j=0;i<n;i+=2,j++);
cout<<"\nThere are ";
cout<<j;
cout<<" odd number between 6 and";
cout<<n;
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Odd numbers in C++?

 
0
  #5
Oct 22nd, 2007
void main is not an improvement, and nor is posting code without using [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 43
Reputation: pacman326@gmail is an unknown quantity at this point 
Solved Threads: 0
pacman326@gmail pacman326@gmail is offline Offline
Light Poster

Re: Odd numbers in C++?

 
0
  #6
Oct 22nd, 2007
Nice for loop

I believe the proper format is
for(int a = x ; a < y; a++)
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,124
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Odd numbers in C++?

 
0
  #7
Oct 23rd, 2007
Salem's request is to repost your code with formatting and Code Tags... When we can read the code, we can help.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2070 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC