943,708 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 495
  • C++ RSS
Jun 1st, 2009
0

Help with for loop

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bolx is offline Offline
7 posts
since Apr 2009
Jun 1st, 2009
0

Re: Help with for loop

Make a for loop that starts from 12 to 1 (Decrementing here )
and then multiply 3 by the index and cout the result.
Reputation Points: 14
Solved Threads: 1
Light Poster
Ahmed_I is offline Offline
32 posts
since Nov 2008
Jun 1st, 2009
-2

Re: Help with for loop

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 7
Solved Threads: 0
Newbie Poster
Mostafa Adel is offline Offline
5 posts
since Feb 2009
Jun 1st, 2009
1

Re: Help with for loop

#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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jun 1st, 2009
0

Re: Help with for loop

Click to Expand / Collapse  Quote originally posted by bolx ...
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
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: -9
Solved Threads: 2
Light Poster
mirfan00 is offline Offline
29 posts
since May 2009
Jun 1st, 2009
0

Re: Help with for loop

Keep it simple:
C++ Syntax (Toggle Plain Text)
  1. for (int i = 12; i; i--)
  2. cout << i << " times 3 = " << 3*i << '\n';
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jun 2nd, 2009
0

Re: Help with for loop

Here it goes..... text file attached!
Attached Files
File Type: txt edit function.txt (2.9 KB, 9 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev06N is offline Offline
6 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ keep image floating within window
Next Thread in C++ Forum Timeline: error LNK 1120 and LNK 2001





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC