Hey guys this is my very first post here looks like a nice site,it helped me a bit when doing my project.anyway my problem is that i have created a rectangle or box with nested for loops and if else statements,i have a next program written that is working but i need to print the out put of this program to out put the calculations within a frame of asterisk's..the program uses switch statements (case) in calculating different answers....finally how can i make all the outputs in each case has the for_loop box around it? Any advice would be greatly appreciated! here is the for_loop code:
1 2 3 4 5 6 7 8 9 10 11 12 13
for(int down = 0; down < 20; down++)
{
for(int across = 0; across < 40; across++)
{
if ( down == 0 || down == 19)
printf("*");
elseif (across == 0 || across ==39)
printf ( "*");
else printf(" ");
}
printf(" \n");
}
where would that code go jjjunk?,the program ask's for input then clears the screen for the output (3 possible results) each of which are within a switch case structure.
#include <iomanip>
#include <iostream>
void PrintNum(double d, int width, int rows)
{
// Top line
for (int i = 0; i < width; ++i)
std::cout << '*';
std::cout << std::endl;
// Middle lines
for (int i = 0; i < rows; ++i)
{
std::cout << '*'; // First character
if (i == rows/2) // If in the middle of rows, print the number
std::cout << std::setw(width-2) << d;
else // Otherwise print blank spaces
for (int j = 0; j < width-2; ++j)
std::cout << ' ';
std::cout << '*' << std::endl; // Last character
}
// Bottom line
for (int i = 0; i < width; ++i)
std::cout << '*';
std::cout << std::endl;
}
Then use it like so:
1 2 3 4 5 6 7 8 9 10 11
int main()
{
double pi = 3.14159;
PrintNum(pi, 40, 9);
}