Okay I spent like 4 hours on this last night and its still not working out for me, so any help you guys can give me would be greatly appreciated.
I'm trying to make a program that will take a odd interget as input and through the use of nested loops make a christmas tree design. All my asterisks must be printed by a single instance of cout<<"*";
l
here is my code so far, please excust how sloppy it is now
i've got it printing out the right number of lines, but if I could just figure out how to write a loop that would make it print the right number of asterisks on each line I could figure out the spaces and formatting myself i think
#include <iostream>
using namespace std;
int main() {
int width;
int blanks;
int quotient;
int product;
int result;
int rows;
int counterw;
int ast;
int rownumber;
int nextline;
int number;
cout << "Enter the width of the base of the tree and press enter.\n";
cin >> width;
counterw = 1;
ast = 1;
number = 1;
nextline = ast;
rows = (width/2) + 1;
rownumber = 1;
blanks = width / 2;
quotient = width / 2;
product = quotient * 2;
result = width - product;
if (result == 0 || width==0 || width >= 80) {
cout << "The number entered was not odd, was 0, or was greater than 80, and a tree will not be drawn. \n";
}
else
cout << "*";
cout << "\n";
while (rows > 1) {
while (ast >=2 ) {
cout << "*";
ast--;
}
nextline = nextline +2;
rows--;
cout << "\n";
}
return EXIT_SUCCESS;
}
I'm trying to make a program that will take a odd interget as input and through the use of nested loops make a christmas tree design. All my asterisks must be printed by a single instance of cout<<"*";
l
here is my code so far, please excust how sloppy it is now
i've got it printing out the right number of lines, but if I could just figure out how to write a loop that would make it print the right number of asterisks on each line I could figure out the spaces and formatting myself i think
#include <iostream>
using namespace std;
int main() {
int width;
int blanks;
int quotient;
int product;
int result;
int rows;
int counterw;
int ast;
int rownumber;
int nextline;
int number;
cout << "Enter the width of the base of the tree and press enter.\n";
cin >> width;
counterw = 1;
ast = 1;
number = 1;
nextline = ast;
rows = (width/2) + 1;
rownumber = 1;
blanks = width / 2;
quotient = width / 2;
product = quotient * 2;
result = width - product;
if (result == 0 || width==0 || width >= 80) {
cout << "The number entered was not odd, was 0, or was greater than 80, and a tree will not be drawn. \n";
}
else
cout << "*";
cout << "\n";
while (rows > 1) {
while (ast >=2 ) {
cout << "*";
ast--;
}
nextline = nextline +2;
rows--;
cout << "\n";
}
return EXIT_SUCCESS;
}