| scotty (15) | |
| .mn | |
|
Last edited on
|
|
| Chervil (1206) | |
|
Why not post the questions in the forum. Actually, I don't think you "need the c++ code for them". What you need is to know how to write the C++ code for them. | |
|
Last edited on
|
|
| JLBorges (1756) | ||
Let's start with this:
Step 1. Write a for loop, which prints all the numbers from 1 to n Post the code for that, and we can then move on to Setep 2. | ||
|
|
||
| scotty (15) | |
| . | |
|
Last edited on
|
|
| JLBorges (1756) | |||
The loop should print all the numbers from 1 to n and nothing else. So, if n is 6, your loop should print 1 2 3 4 5 6 - nothing more, nothing less. Give it another try. | |||
|
|
|||
| scotty (15) | |
| . | |
|
Last edited on
|
|
| JLBorges (1756) | |||
Now modify this program so that it prints n asterisks. If n is 8, the program should print ******** Write it, compile it, and run it. And after that, post the code. | |||
|
Last edited on
|
|||
| Fourc00h (7) | |
|
God damn I just had a shot at this, took me a while, I had the new line inside the nested for loop so it was just showing * * * * * Finally got it! | |
|
|
|
| scotty (15) | |
| . | |
|
Last edited on
|
|
| JLBorges (1756) | |
|
> would you change the 1 after cout<< to an * It is not 1, it is i. And yes, that i would be changed to a '*' (within quotes). > I don't have the software until tomorrow Ok, it would be best to wait till you have a C++ compiler, and then you can actually try things out. | |
|
|
|
| Fourc00h (7) | |
|
Why don't you download Visual Studio or DevC++ ? they're free What I did to debug it was to add i's number in the loop to see where it stops moving ahead, like cout<<i<<". "<<j; So it would print something like this out: 1. 0 2. 0 2. 1 3. 0 3. 1 3. 2 So on.. | |
|
|
|
| scotty (15) | |
| . | |
|
Last edited on
|
|
| Fourc00h (7) | |
|
Ok, when you have time tomorrow download gcc Here's a guide that may help you out: http://www.mkyong.com/mac/how-to-install-gcc-compiler-on-mac-os-x/ | |
|
|
|
| JLBorges (1756) | |
|
> I have a mac, and I haven't been able to fine anything free to download. Xcode is free: http://developer.apple.com/xcode/ If you prefer a pure C++ IDE: http://codelite.org/LiteEditor/Download | |
|
Last edited on
|
|
| scotty (15) | |
|
#include <iostream> int main() { int n = 6 ; // print numbers 1 to n for( int i = 1 ; i <= n ; ++i ) std::cout << "*" ; std::cout << '\n' ; // and print a new line at the end } so from here what would be the next step? | |
|
|
|
| JLBorges (1756) | |
|
> so from here what would be the next step? Now write two loops; with the inner one nested inside the outer loop. In the outer loop, vary n from 1 to 6. For each value of n in the outer loop, print a line containing n asterisks. | |
|
|
|
| scotty (15) | |
|
#include <iostream> intmain() { int n= 6; // print numbers 1 to n for (int T = 1; T <= num_entered; T++) std::cout<<"*" ; { for (int Y = 0; Y < T; Y++) { how would i finish this off? | |
|
|
|
| JLBorges (1756) | |||
|
Keep the inner loop and the line following it just the same as the earlier program. Write an outer loop varying n from one to 6 around it
| |||
|
|
|||
| vlad from moscow (3662) | |||
| |||
|
Last edited on
|
|||
| vlad from moscow (3662) | |||
Another possible code
| |||
|
|
|||