Computing.Net > Forums > Programming > Help with a C Program / Newbie

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with a C Program / Newbie

Reply to Message Icon

Name: alocaco
Date: October 2, 2003 at 22:11:54 Pacific
OS: WinXP
CPU/Ram: 768
Comment:

Hi,
I was wandering if anybody here could help me out with a programming assigment i have to do. I'm not asking for the total solution, I really want to learn this stuff, but i need some help with loops in C. We are supposed to make a program that will produce a parallelogram of "*" after a user has inputed the width and height. Here is a link to get the actual program description: http://www.geocities.com/alocaco2k1/program3.doc
If somebody could just show me what a loop that does something like this I would be very greatful. Also we have another programming assigment due at a later date where we have to do some error cheking (which i'm pretty sure i can do) and take an integer and display its positive factors. Again, im kinda stuck with how to get and display the factors. again here is a link to download the specifics: http://www.geocities.com/alocaco2k1/program4.doc

Much thanks to anyone who can help me out.

***Note: these programs will be compiled with gcc and run on a unix platform.



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: October 2, 2003 at 22:16:49 Pacific
Reply:

You'll get more help if you start and then show us what you've tried and then ask for help.


0

Response Number 2
Name: Infinite Recursion
Date: October 6, 2003 at 12:56:46 Pacific
Reply:

I agree with Don. Start on the assignments,
show us what you have and where it fails. Then we will be more helpful when offering a range of solutions. Do not just give us your specs and expect us to write the code for you. Many months ago, I had a rant about homework, perhaps you can find it in the thread archives.

IR


0

Response Number 3
Name: alocaco
Date: October 7, 2003 at 17:55:10 Pacific
Reply:

ok i have done what you guys suggested. Like I said before, im not asking for entire solutions, i didnt mean to come across that way. Anyway i have started the first program (Program3 - The Parallelogram) and I can't figure out what to do now. I have everything upto the output of the width of the parallelogram. Here is what i have so far: http://www.geocities.com/alocaco2k1/program3.c

i tried making the variables integers, floats, doubles, etc. and i just left them as doubles. If anyone can help me out with this i would be greatly appriciative. Thanks.


0

Response Number 4
Name: Infinite Recursion
Date: October 7, 2003 at 20:22:53 Pacific
Reply:

This code will print the correct number of rows and columns, I will leave the spacing for you to figure out... its fairly trivial.
Hopefully, my code below will clear up any problems or concerns you have.

IR


---


#include <stdio.h>

int main(void)
{
double length, width, counter;

//Gather Specifications
printf("Enter the length of your parallelogram.\n");
scanf("%lf", &length);
printf("Enter the width of your parallelogram.\n");
scanf("%lf", &width);

//Varify length and width
//printf("Length equals = %.0lf\n", length);
//printf("Width equals = %.0lf\n", width);

//Width of Parallelogram
int rows = 0;
int cols = 0;

while (cols <= width - 1)
{
while (rows <= length - 1)
{
printf("*");
//return counter;
rows++;
}
printf ("\n");
rows = 0;
cols++;
}
system("pause");

return 0;
}


0

Response Number 5
Name: alocaco
Date: October 8, 2003 at 19:18:55 Pacific
Reply:

Thanks a bunch IR, that seems to work very well. The only problem i am still having is getting the printed parallelogram to skew to the right one space for each row after the first. Do i have to right another loop just to do that or can i modify the current loops? Thanks.


0

Related Posts

See More



Response Number 6
Name: Infinite Recursion
Date: October 8, 2003 at 20:03:51 Pacific
Reply:

Yup, I know that is a problem... didn't want to give you the entire assignment.

You could do it either way... I would write a function called Spacer, pass it a integer value (of the current counter)... and return a string consisting of that many spaces to display it before each newline, but you can attack it which ever way you want.

IR


0

Response Number 7
Name: alocaco
Date: October 8, 2003 at 20:20:39 Pacific
Reply:

I think that went a little over my head. I'm not asking for the exact solution but could you give me an example of somthing like what you said? Sorry for so many questions it's just that my instructor didn't really explain any of this all to well in class. I'm trying to learn this with as little help as possible but I seem to learn best if people show me what to do then i can assimilate it to my own needs. Thanks again.


0

Response Number 8
Name: Infinite Recursion
Date: October 9, 2003 at 20:31:50 Pacific
Reply:

something like this...

string Spacer (int numSpaces)
{
int i = 0;
string whiteSpace;
while (i < numSpaces)
{
whiteSpace = whiteSpace + " ";
i++;
}
return whiteSpace;
}

.......

Call it in your while loop that we defined previously, where you want spacing added, using this...

Spacer(amount_of_space_you_want);

I suggest, you use the value of your current index so you can have the exact indentation on each pass of the loop.

IR


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with a C Program / Newbie

Help with my C++ program www.computing.net/answers/programming/help-with-my-c-program/1813.html

Help with making C++ Program www.computing.net/answers/programming/help-with-making-c-program/4217.html

Need help with C++? www.computing.net/answers/programming/need-help-with-c/4642.html