C program help ASAP  | | |
February 21st, 2007, 08:56 PM
|
#1 (permalink)
| | Member
Join Date: Dec 2004 Location: Va Bch. VA
Posts: 134
|
I'm on my last question of my final: MUST USE NESTED FOR LOOPS
I need to write a program that accepts 5 integers between 1 & 30 and then print out that number of asterisks.
Sample Output
Enter five numbers between 1 & 30: 1 2 3 4 5
*
**
***
****
*****
__________________
Self built:
Abit AS8, 3.4GHz P4, 2Gig RAM, Radeon 9800, Audigy 2 ZS, 16x DL DVD, Internal SD/XD reader, WD HDD
Last edited by sectshun8 : February 21st, 2007 at 09:09 PM.
|
| |
February 21st, 2007, 11:30 PM
|
#2 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
|
What part of this do you need help on.....
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
|
| |
February 21st, 2007, 11:36 PM
|
#3 (permalink)
| | Mobile Member
Join Date: Apr 2005 Location: S. Central PA
Posts: 3,602
|
is this a console based app? if so is it C++ or just C?
__________________ Thinkpad T61 14.1" wide | WinXP Pro | C2D T8300 CPU | 3GB DDR2 | 160GB HDD | AGN & WWAN
Lenovo S10 10.2" LED display | 1.6Ghz Atom CPU | 1GB DDR2 | 1.3mp webcam | B/G WiFi | 160GB HDD |
| |
February 22nd, 2007, 08:40 AM
|
#4 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
|
ok this is off the top of my head Code: int x[5];
cin >> x[0];
cin >> x[1];
cin >> x[2];
cin >> x[3];
cin >> x[4];
for(int i=0; i<0; i++) //1 loop
{
for(int j=; j<x[i]; j++)//2nd nested loop
{
cout << "* ";
}
cout << endl;
}
substitute count for printf if u can't use the std - i can't remember the sub for cin - sorry |
| |
February 23rd, 2007, 02:30 PM
|
#5 (permalink)
| | Senior Member
Join Date: Jul 2002 Location: Texas A&M
Posts: 611
| Quote:
Originally Posted by exally substitute count for printf if u can't use the std - i can't remember the sub for cin - sorry | scanf
__________________
The Terk
|
| |
February 23rd, 2007, 04:12 PM
|
#6 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
| Quote:
Originally Posted by exally ok this is off the top of my head Code: int x[5];
cin >> x[0];
cin >> x[1];
cin >> x[2];
cin >> x[3];
cin >> x[4];
for(int i=0; i<0; i++) //1 loop
{
for(int j=; j<x[i]; j++)//2nd nested loop
{
cout << "* ";
}
cout << endl;
}
substitute count for printf if u can't use the std - i can't remember the sub for cin - sorry | If this is a question on his final and he has no clue how to do this, you are certinaly not helping him by giving him the code.... Well unless he wants to become a VB programmer that is *hides*
In all seriousness though, don't post solutions to peoples homework/tests. Pseudocode, no problem, but at least make them figure out syntax for themselves, especially when it is as basic as this. Last check this wasn't CheatIMO. (Though it is almost an anagram)
Jkrohn |
| |
February 24th, 2007, 12:00 AM
|
#7 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
| Quote:
Originally Posted by jkrohn If this is a question on his final and he has no clue how to do this, you are certinaly not helping him by giving him the code.... Well unless he wants to become a VB programmer that is  *hides*
In all seriousness though, don't post solutions to peoples homework/tests. Pseudocode, no problem, but at least make them figure out syntax for themselves, especially when it is as basic as this. Last check this wasn't CheatIMO. (Though it is almost an anagram)
Jkrohn |
at his level what good would psuedo code do??? it would probably confuse him more than anything -> if he can't understand that code then there is no hope for him... it is simple create an array, fill the array, use a loop to navigate the array, use the nested loop to output the array data.... atleast i didn't use tab indexing so he atleast has to discover whats going on there.... in this case i was right to give him the code.
plus by glancing at the code there is major error - so if he used the code would have to go through it line by line to discover this error
Last edited by exally : February 24th, 2007 at 12:02 AM.
|
| |
February 24th, 2007, 01:26 AM
|
#8 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
| Quote: |
if he can't understand that code then there is no hope for him.
| If he can't understand how to even start this question on his final then he needs to be taught something. Giving him code will help him zero. And yes that entire problem IS simple, which is why it is even more alarming he simply asked "how do you do it" which is even more reason to try to teach him the logic behind it and leave the syntax to him. |
| |
February 24th, 2007, 04:02 AM
|
#9 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
|
it is pointless anyway john - he submitted that on 22nd, i answered on the 24th so he would have been finished. |
| |
February 27th, 2007, 10:07 PM
|
#10 (permalink)
| | Caveat Emptor
Join Date: Mar 2005 Location: Out of my mind
Posts: 3,242
|
I know it's old, but fun nonetheless  Sorry, a little rusty on C++, might not be *perfect*! Didn't put in check for numbers 1 to 30 either Code: int i=0, input=0;
while(1) // infinite loop ;)
++i; // first number
if(i==5) // loop exit
break;
else {
cin >> input;
for(int x=0;x<input;++x)
cout << '*' << '\n';
}
end-while
Last edited by Rootstonian : February 27th, 2007 at 10:10 PM.
|
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |