473,471 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hello can anyone help with While loops and setting widths?

3 New Member
Am I doing something wrong with setting my width? I thought I had it correct.
Can any inform me on how to write 4 different while or do-while loops counting down to 0, it has to be lined up column by column.
Example:
Expand|Select|Wrap|Line Numbers
  1. Days       hours        Minutes
  2. -------       ---------       ------------
  3. 0              96                382
  4. 1              72                 . 
  5. 2              48                 .
  6. 3              24
. .
. .

something like that......... I don't know how to keep the while statements on the same row. I'm kind of new to this.
Oh and here's the width and the while pgm i'm having problems with.


Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. #include <iomanip>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //Declaring variables.
  10.     int can, mis;
  11.     double misleft;
  12.  
  13.  
  14.  
  15.  
  16. //Prompting users input for num. of cannibals.
  17.     cout<<"Please enter a number equal or greater than 10"<<'\n'<<"for the amount of cannibals!"<<"  ";
  18.     cin>>can;
  19.     cout<<endl;
  20. //Prompt user input for num. of missionaries.
  21.     cout<<"Please enter a number equal or greater than 5"<<'\n'<<"for the amount of missionaries to be saved!"<<"  ";
  22.     cin>>mis;
  23.     cout<<endl;
  24.     cout<<"              "<<"ThankYou!"<<endl;
  25.     cout<<endl;
  26.     cout<<endl;                                                          //Spacing out lines
  27.  
  28. //Calculated pgm cout formation to display End of hr, miss. left, cann. eating, tarz. dist., and curr. miss lft.
  29. //Setting width within statement.
  30.     cout<<"END OF HOUR"<<setw(10)<<"MISSIONARIES LEFT"<<setw(10)<<"CANNIBALS EATING"<<setw(10)<<"TARZAN DISTANCE"<<setw(10)<<"CURR MISS BEING EATEN"<<endl;
  31.     cout<<"------------"<<setw(10)<<"-----------------"<<setw(10)<<"----------------"<<setw(10)<<"---------------"<<setw(10)<<"--------------------"<<endl;
  32.     cout<<endl;
  33.  
  34. //for statement to calc. hours.
  35.     for (int hours = 0; hours < 31; hours++)
  36.             cout<<hours<<'\n';
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.     return 0;
  47.  
  48.  
  49.  
  50. }
Sep 30 '07 #1
1 1480
hsn
237 New Member
first of all to make the columes much better just use "\t" rather than setw()
and then to disply them as you are showing them you have to display them at the same time in one FOR or WHILE loop
that is much better way

GOOD LUCK
Sep 30 '07 #2

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

Similar topics

1
by: Byron O'Neal | last post by:
Using Visual Basic .net 2003 How do I set column widths of a GridControl when a form loads? Thanks for any assistance Byron
11
by: Shawn Milo | last post by:
I put this together yesterday, and I thought I'd share it. It works in both IE and Mozilla Firefox. I posted something similar to this months back, but it was much longer, and only worked in IE....
5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
2
by: Byron O'Neal | last post by:
Using Visual Basic .net 2003 How do I set column widths of a GridControl when a form loads? Thanks for any assistance Byron
6
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000...
1
by: jawolter | last post by:
I have a div that uses the overflow:hidden;text-overflow:eillipsis;white-space:nowrap css tags. This holds a very long line of text which fills any percentage of the screen's width. If I make the...
11
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html I've ended up with what seems like a rather complex structure for what I thought would be a somewhat simple...
2
by: Amanda | last post by:
please take a look at: shannon.amandadevries.com 1. in firefox, the 'content' div should be starting on the right-hand side of the menublock, not all the way down at the 'copyrightblock'....
3
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I am wondering what is considered a best practice for setting column widths to fit the data for a DataGridView (.Net 2.0) that was created on-the-fly from an arbitrary query. What I would probably...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.