Help with for loop

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

Join Date: Apr 2009
Posts: 7
Reputation: bolx is an unknown quantity at this point 
Solved Threads: 0
bolx bolx is offline Offline
Newbie Poster

Help with for loop

 
0
  #1
Jun 1st, 2009
Hi, im new to c++ and wondered if anyone could help me with this

Use a for loop to display 3 times table backwards

12 times 3 = 36
11 times 3 = 33
10 times 3 = 30
9 times 3 = 27
8 times 3 = 24
7 times 3 = 21
6 times 3 = 18
5 times 3 = 15
4 times 3 = 12
3 times 3 = 9
2 times 3 = 6
1 times 3 = 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 32
Reputation: Ahmed_I is an unknown quantity at this point 
Solved Threads: 1
Ahmed_I Ahmed_I is offline Offline
Light Poster

Re: Help with for loop

 
0
  #2
Jun 1st, 2009
Make a for loop that starts from 12 to 1 (Decrementing here )
and then multiply 3 by the index and cout the result.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: Mostafa Adel is an unknown quantity at this point 
Solved Threads: 0
Mostafa Adel's Avatar
Mostafa Adel Mostafa Adel is offline Offline
Newbie Poster

Re: Help with for loop

 
-2
  #3
Jun 1st, 2009
  1. #include<iostream.h>
  2.  
  3. main(){
  4. int answer;
  5. for(int index = 12; index >= 1; i--){
  6. answer=3*i;
  7. cout<<index<<" times 3 = "<<answer<<endl;
  8. }
  9. }
Iwish that hels you GOOD LUCKk
Last edited by Narue; Jun 1st, 2009 at 3:29 pm. Reason: added code tags
With my best wishes=>mostafa_adel01@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help with for loop

 
1
  #4
Jun 1st, 2009
Originally Posted by Mostafa Adel View Post
#include<iostream.h>

main(){
int answer;
for(int index = 12; index >= 1; i--){
answer=3*i;
cout<<index<<" times 3 = "<<answer<<endl;
}
}

Iwish that hels you GOOD LUCKk
-iostream.h should be iostream
-it's int main
-you're mixing index with the variable i

etc etc and use [code][/code] tags next time.
Last edited by iamthwee; Jun 1st, 2009 at 6:53 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 27
Reputation: mirfan00 has a little shameless behaviour in the past 
Solved Threads: 2
mirfan00 mirfan00 is offline Offline
Light Poster

Re: Help with for loop

 
0
  #5
Jun 1st, 2009
Originally Posted by bolx View Post
Hi, im new to c++ and wondered if anyone could help me with this

Use a for loop to display 3 times table backwards

12 times 3 = 36
11 times 3 = 33
10 times 3 = 30
9 times 3 = 27
8 times 3 = 24
7 times 3 = 21
6 times 3 = 18
5 times 3 = 15
4 times 3 = 12
3 times 3 = 9
2 times 3 = 6
1 times 3 = 3
  1. #include<iostream.h>
  2.  
  3. main(){
  4. int multiply;
  5. // for loop for 12 times
  6. for(int count = 12;count >= ;count--){
  7. multiply = 3*count;
  8. cout << count << " times 3 = " <<multiply << endl;
  9. }//for
  10.  
  11. return 0;
  12. }
I hope you enjoy it.
Last edited by Tekmaven; Jun 1st, 2009 at 4:15 pm. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Help with for loop

 
0
  #6
Jun 1st, 2009
Keep it simple:
  1. for (int i = 12; i; i--)
  2. cout << i << " times 3 = " << 3*i << '\n';
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 6
Reputation: Kev06N is an unknown quantity at this point 
Solved Threads: 0
Kev06N Kev06N is offline Offline
Newbie Poster

Re: Help with for loop

 
0
  #7
Jun 2nd, 2009
Here it goes..... text file attached!
Attached Files
File Type: txt edit function.txt (2.9 KB, 4 views)
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC