474,050 Members | 5,113 Online
Bytes | Software Development & Data Engineering Community
+ 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 1509
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
1845
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
2101
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. Shawn function searchList(inText, drpBox){ var iCount;
5
5314
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 specification for each column (e.g. printf(%10s %25s %15s\n", pszCol1, pszCol2, pszCol3)). My problem is that when a string is longer the column's width, it overflows the column and takes the table out of alignment. What I want it to do is word-wrap...
2
1121
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
7121
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 datagrid1.columns(1).width = 1000 Except that there is no such things as a columns collection in a datagrid.
1
7144
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 screen more narrow--less of the line of text shows, and dot dot dot shows at the end to indicate more text is in the line. </div> <div STYLE="clear:none;width:45%;white-space:nowrap;border:thin solid...
11
5041
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 problem. Even that complex solution works well only in FireFox (haven't tested Safari...). Can anyone come up with a better solution, where 'better' means: - Works as well as the example above, but is simpler. OR
2
1990
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'. what gives? 2. why is 'container' not being centred in IE? i have a site that is very similar to this in terms of it CSS, which is correctly centred...
3
6779
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 do is scan the width of each column for the first couple hundred or so rows and find the largest. (But how does one convert character counts to field widths in pixels?) More generally, however, is there a better approach to accomplish this?
0
10557
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
12168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11619
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12057
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10340
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5432
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.