Help with loop
Dec 3, 2011 at 8:59pm UTC
I need to repeat this line 3 more times but i'm not sure how to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
int rowcount = 0;
int widthcount = 0;
while (widthcount <= 12)
{
if (widthcount <= 12)
{
printf("*" );
widthcount++;
}
else
printf("\n" );
}
printf("\n" );
system ("pause" );
return 0;
}
Dec 3, 2011 at 9:06pm UTC
first what line do you need to repeat second if you want proper syntax:
stdio.h --> iostream
stdlib.h --> cstdlib
math.h --> cmath
printf("") --> cout<<""
Dec 3, 2011 at 9:07pm UTC
well i need the while loop to repeat so it makes something like this:
*************
*************
*************
*************
and ok thanks
Dec 3, 2011 at 9:11pm UTC
Put another loop around it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main (){
int rowcount = 0;
int widthcount = 0;
while (rowcount < 4){
while (widthcount < 13){
printf("*" );
widthcount++;
}
printf("\n" );
rowcount++;
}
system ("pause" );
return 0;
}
Last edited on Dec 3, 2011 at 9:11pm UTC
Dec 3, 2011 at 9:14pm UTC
ok how about this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int loop_through = 1, star_out = 0;
while (loop_through <= 4)
{
while (star_out < 13)
{
cout<<"*" ;
star_out++;
}
if (star_out == 13)
{
cout<<"\n" ;
loop_through++;
star_out = 0;
}
}
exit (1);
}
Dec 3, 2011 at 9:16pm UTC
Thank you i just kept putting the rowcount++ in the wrong spot
Topic archived. No new replies allowed.