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

Help with for loop

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

bolx
Newbie Poster
7 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Make a for loop that starts from 12 to 1 (Decrementing here )
and then multiply 3 by the index and cout the result.

Ahmed_I
Light Poster
32 posts since Nov 2008
Reputation Points: 14
Solved Threads: 1
 
#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:D

Mostafa Adel
Newbie Poster
5 posts since Feb 2009
Reputation Points: 7
Solved Threads: 0
 

#include

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

-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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

#include<iostream.h>

main(){
int multiply;
// for loop for 12 times
for(int count = 12;count >=  ;count--){
    multiply = 3*count;
   cout << count << "  times 3 = " <<multiply << endl;
}//for

return 0;
}

I hope you enjoy it.

mirfan00
Light Poster
29 posts since May 2009
Reputation Points: -9
Solved Threads: 2
 

Keep it simple:

for (int i = 12; i; i--)
  cout << i << " times 3 = " << 3*i << '\n';

;)

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

Here it goes..... text file attached!

Attachments edit_function.txt (2.87KB)
Kev06N
Newbie Poster
6 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You