473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Formatting output with C++

i need to form this table and i have no idea how to figure it out can somebody please help or at least give me a hint. please!


----------------------------------------------------------
X X^2 X^3
1.0e+000 1.00e+000 1.00e+000
2.0e+000 4.00e+000 8.00e+000
3.0e+000 9.00e+000 2.70e+001
4.0e+000 1.60e+001 6.40e+001
5.0e+000 2.50e+001 1.25e+002
6.0e+000 3.60e+001 2.16e+002
7.0e+000 4.90e+001 3.43e+002
8.0e+000 6.40e+001 5.12e+002
9.0e+000 8.10e+001 7.29e+002
1.0e+001 1.00e+002 1.00e+003
1.1e+001 1.21e+002 1.33e+003
1.2e+001 1.44e+002 1.73e+003
1.3e+001 1.69e+002 2.20e+003
1.4e+001 1.96e+002 2.74e+003
1.5e+001 2.25e+002 3.38e+003
----------------------------------------------------------
Aug 12 '07 #1
9 3491
weaknessforcats
9,208 Expert Mod 8TB
It looks like you have already done it.

Column 1 is X (a double)
Column 2 is X squared (a double)
Column 3 is X cubed (double)

You don't actually need a table of all three values becuse you can create the squares and the cubes as needed.

Now you are down to a simple array of double with elements initialized to the values of X.
Aug 12 '07 #2
archonmagnus
113 100+
If you are referring to formatting the table as your post shows, look at the library, "iomanip"--specifically the objects "setiosflags()", "setprecision()", and (possibly) "setw()".
Aug 12 '07 #3
i have to actually format it and have a starting and final number for the table
Aug 13 '07 #4
sicarie
4,677 Expert Mod 4TB
i have to actually format it and have a starting and final number for the table
Well, it seems you have been helped in how to format it, now you just need to decide on your final number... Unless you have a more specific question?
Aug 13 '07 #5
I have this at d moment but cant seem 2 get it into exponential format


Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int xA,xB,xTwo,xThree,i;
  8.  
  9.     printf("Two numbers must be entered second number should be higher than first.");
  10.     printf("\nThey should both be whole number\n\n\n");
  11.     printf("Enter first number: ");
  12.     scanf("%d",&xA);
  13.     printf("Enter second number: ");
  14.     scanf("%d",&xB);
  15.     printf("\n\n\n---------------------------------\n");
  16.     printf("Table of Information\n\n");
  17.     printf("---------------------------------\n");
  18.     printf("X           X^2            X^3\n");
  19.     while(xA<=xB)
  20.     {
  21.                  xTwo = xA*xA;
  22.                  xThree = xTwo*xA;
  23.                  printf("%d          %d          %d\n",xA,xTwo,xThree);
  24.                  xA++;
  25.     }
  26.     printf("---------------------------------\n");
  27.     system("pause");
  28.     return 0;
  29. }
Aug 15 '07 #6
sicarie
4,677 Expert Mod 4TB
Sinanny-

I'm gonna take a look at your code in just a minute here (some housekeeping things I need to do first), but if you could also read through the Posting Guidelines I'd appreciate it. You didn't do anything big, but we appreciate people using code tags and that sort of thing (I think I also changed the thread title on this, but I'm not sure - that's in there too). So if you could give that a look, we'd be grateful.

Thanks,

sicarie
Aug 15 '07 #7
sicarie
4,677 Expert Mod 4TB
Sinanny-

By "exponential" do you mean the scientific notation like 2.70e+001 ?
Aug 15 '07 #8
RRick
463 Expert 256MB
It looks like your problem is in the printf statement. You're using %d which deals with integers. Are you getting any decimals values at all?

Experiment with %e (or maybe f or g). The syntax is pretty weird but something like %12.6e3 should get you close.
Aug 16 '07 #9
By exponential i do mean 1.0e+00.
I have tried using %e and %f etc but just doesnt seem to work
Aug 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Tom Petersen | last post by:
Here is a little more info, sorry should have explained what my final goal was. I am creating a .vcs file from a form to import into Outlook. I was just testing the output on screen then pasting...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
6
by: shoo | last post by:
Any one know how to do this? thank Write a simple text-formatting program that produces neatly printed output from input text containing embedded command lines that determine how to format the...
7
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some...
2
by: Ken Wilson | last post by:
I am writing and .xml file and am not getting the formatting I would like. The portion of the code that is giving me problems is as follows; XmlTextWriter tw = new XmlTextWriter(filename); ...
8
by: Vinay Jain | last post by:
Hi.. I am newbe in postgresql so please help me though the question may be very easy to answer.. Is there any formatting function to get output with fix lengths..for example my query is.. schema...
9
by: sck10 | last post by:
Hello, I have a page with an ImageButton that is used to redirect to another page. When the page first opens, everything looks as expected. However, when I click on the image, the new page...
6
by: Rafael Olarte | last post by:
The goal of this project is to output the following information as follows: 34.5 38.6 4.1 42.4 3.8 close 46.8 4.4 big change. The values of the first colunm are obtain from a file...
1
by: AJG | last post by:
Hi there. I am using a library called SOCI that has a method to set a stream which it uses to log SQL queries. The signature is as follows: void setLogStream(std::ostream *s); This works great...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.