Thursday, July 30, 2009

In C++ I wrote a program to printout a "chart", I need help making an "underline" appear.

Okay so for a school Assignment I had to program a chart to display 3 columns and 10 rows. The columns headers need to be "underlined". I am stuck trying to figure out how to do that, any idea's please.





A chunk of my current code is:








#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;cmath%26gt;





using namespace std;





int square(int);


int cube(int);





int main()





{





int x;


x=1;





cout %26lt;%26lt; setw(8) %26lt;%26lt; "Number" %26lt;%26lt; setw(9) %26lt;%26lt; "Square" %26lt;%26lt; setw(12) %26lt;%26lt; "Cube\n" %26lt;%26lt; endl;


cout %26lt;%26lt; setw(8) %26lt;%26lt; x %26lt;%26lt; setw(9) %26lt;%26lt; square(x) %26lt;%26lt; setw(12) %26lt;%26lt; cube(x) %26lt;%26lt; endl;


cout %26lt;%26lt; setw(8) %26lt;%26lt; x+1 %26lt;%26lt; setw(9) %26lt;%26lt; square(x+1) %26lt;%26lt; setw(12) %26lt;%26lt; cube(x+1) %26lt;%26lt; endl;





return 0;





}











I need an underline to seperate "Number Square Cube" from the rest of the chart.





any help would be great.





Thanks!!!!

In C++ I wrote a program to printout a "chart", I need help making an "underline" appear.
in console u must use special character combination to draw the line
Reply:i dont remember C too clearly but why dont you use a for loop





for(i=1;i%26lt;=80;i++)


{


cout%26lt;%26lt;"_";


}





cout%26lt;%26lt;"\n";





Sorry i know its in c++ but i dont remember the syntax right now of C
Reply:I'm pretty sure you can't format characters that are output to the console window. The best you can do for underline is to output appropriately spaced dashes ( ---------- ) or underbars in the next line. If you want to do underbars, you need to escape them: "\_\_\_\_"

artificial flowers

No comments:

Post a Comment