C ++新手/输出文件布局/ For循环 [英] C++ Newbie / Output File Layout/ For Loop

查看:94
本文介绍了C ++新手/输出文件布局/ For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨eveyone。我是C ++的新手并且有一个任务即将发布。除了两个部分,我理解其中的大部分内容。 For循环和输出文件中的布局。作业是邮寄标签。它们将采用以下格式:

迈克尔史密斯

555史密斯街

费城,宾夕法尼亚州15728

方框1 5美元

老师希望他们打印

BOX 1 BOX2

BOX 3 BOX 4

BOX5

如何分割这样的页面并强制程序以这种方式打印它们。也是for循环我有点不确定如何把它放在一起。任何人都可以解释一下for循环吗?多谢你们。您可以提供任何帮助。

Hi eveyone. I am very new to C++ and have an assignment coming up. I understand most of it except for two parts. The For Loop and the layout in the output file. The assignment is to do mailing labels. They will be in the format:
Michael Smith
555 Smith Street
Philadelphia, PA 15728
Box 1 of 5

The teacher wants them to be printed
BOX 1 BOX2
BOX 3 BOX 4
BOX5

How would I go about splitting the page like that and forcing the program to print them that way. Also the for loop I am a bit uncertain of how to put it together. Can anyone maybe explain the for loop a little? Thanks guys. Any help you can provide would be so appreciated.

推荐答案

为了以这种方式打印,您必须打印第一个独立的BOX 1, BOX 2的第一行,然后是换行符,然后是BOX 1的第二行,然后是BOX 2的第二行,然后是换行符等,与BOX 3和BOX 4重复相同的方式。


至于for ...循环,它实际上取决于你想如何使用它。 for循环本身非常简单 - 你究竟使用循环做什么,你不明白什么?
In order to print in that way, you''d have to print the first lone of BOX 1, the first line of BOX 2, then a newline character, then the second line of BOX 1, then the second line of BOX 2, then a newline character, etc. etc, repeating the same way with BOX 3 and BOX 4.

As for the for...loop, it really depends on how you want to use it. For loops in and of themselves are very simple - what exactly are you using the loop to do, and what don''t you understand?


如果你正在做同样的邮件标签和每次重复,你可以创建一个变量(很可能是一个字符串),然后使用for循环将其打印出来。


for循环设置如下:
If you are doing the same mailing label over and over again each time, you can create a variable (most likely a string) and then use the for loop to print it out.

The for loop is setup as follows:
展开 | 选择 | Wrap | 行号


谢谢你的帮助。对于增量计数器,我会添加类似的东西。


box_number = 1;

cin>>姓名;

cin>> street_address;

cin>> city,state,zip_code;

cin>> &]方块" >> box_number ++>> "&的QUOT; >> number_of_boxes>> ''\ n'';

但我怎么能确定它停止说这个人进5个盒子。如何让它停在那里?
Thanks that was helpful. For the increment counter would I put something like.

box_number = 1;
cin >> name;
cin >> street_address;
cin >> city, state, zip_code;
cin >> "Box" >> box_number++ >> "of" >> number_of_boxes>> ''\n'';
But how do I make sure it stops at say the person enters 5 boxes. How do I make it stop there?


这篇关于C ++新手/输出文件布局/ For循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆