Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,676 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,202 people online right now. Registration is fast and FREE... Join Now!




Controlling in and output

 
Reply to this topicStart new topic

Controlling in and output, Cin and Cout

Syntax_Terror
post 3 Sep, 2007 - 04:12 AM
Post #1


D.I.C Head

**
Joined: 3 Sep, 2007
Posts: 204


My Contributions


This is my first week with C++. I have tried a few different things, but can not seem to control the input and out puts... Thus I have 3 questions.
All three are console apps if it matters.....
Question 1.

CODE

        ...
        int boxes [10][10]={
        {8,10,2,4,5,3,0,0,0,0},
        {0,0,0,1,0,0,0,0,0,0},
        {0,0,0,0,0,0,1,0,0,0},
        {0,0,1,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,1,0,0},
        {0,0,0,10,0,0,0,0,0,0},
        {0,0,10,0,0,0,0,0,0,0},
        {11,1,0,0,0,0,0,0,0,0},
        {10,0,0,0,0,0,0,0,0,0},
        {1,9,6,7,0,0,0,0,0,0},
        {0,8,0,0,0,0,0,0,0,0}
};

for (i=1;i<=10;i++){
for (x=1;x<=10;x++){
cout >> boxes [i] [x] >> endl;
}
}



This displays the screen as
8
10
2
4
5
3
0
0
0
0
...
and so on......

How do I make it display as
"8 10 2 4 5 3 0 0 0 0"?

Question 2.

CODE

.....
cout >> "Input your answer." >> endl;
cin answer


This displays the question, and has you answer on the next line as so,

Input your answer.
24 <<<< User input

how may I get it to answer on the same line as the question as so...

Input your answer. 24

and lastly, Question 3.
How do you control the size of the "dos box" your computer runs in I want it to run in full screen mode?


User is offlineProfile CardPM

Go to the top of the page

Bench
post 3 Sep, 2007 - 04:37 AM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


What is your actual code? What you've pasted here won't compile.
CODE
for (i=1;i<=10;i++){
for (x=1;x<=10;x++){
cout >> boxes [i] [x] >> endl;
}
}
First of all, the output operator is <<

Also remember that arrays are indexed from zero. so for a 10-element array, your indices are 0-9.

CODE
for (i=0; i<10; i++)
{
    for (x=0; x<10; x++)
    {
        cout << boxes [i] [x] << endl;
    }
}



As for the layout of your output.. Have a look where your end-of-line endl appears... endl causes a new-line character to be placed on the output stream.

This post has been edited by Bench: 3 Sep, 2007 - 05:25 AM
User is offlineProfile CardPM

Go to the top of the page

quim
post 3 Sep, 2007 - 05:29 AM
Post #3


D.I.C Head

Group Icon
Joined: 11 Dec, 2005
Posts: 145



Thanked 2 times

Dream Kudos: 350
My Contributions


also, in continuity to what Bench said. watch out for these syntax error, they are very literal. blink.gif
QUOTE
CODE
.....
cout >> "Input your answer." >> endl;
cin answer

use the extractor operator >> for cin. you want to input in the same line do not make a new line like:
CODE
cout <<endl;//or
cout << "\n";

this way your program will not make a new line and you will be able to enter the input in the same like of you output. wink2.gif

This post has been edited by quim: 3 Sep, 2007 - 05:30 AM
User is offlineProfile CardPM

Go to the top of the page

Syntax_Terror
post 3 Sep, 2007 - 06:52 AM
Post #4


D.I.C Head

**
Joined: 3 Sep, 2007
Posts: 204


My Contributions



Thanks.

No, that wasn't my actual code, I was just trying to give you a rough ideas of what I needed. Please pardon the typo's... I wasn't aware you needed the exact code to explain a concept, but I will include the actual code from now on... sorry.

ST
User is offlineProfile CardPM

Go to the top of the page

Bench
post 3 Sep, 2007 - 07:06 AM
Post #5


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


QUOTE(Syntax_Terror @ 3 Sep, 2007 - 03:52 PM) *

Thanks.

No, that wasn't my actual code, I was just trying to give you a rough ideas of what I needed. Please pardon the typo's... I wasn't aware you needed the exact code to explain a concept, but I will include the actual code from now on... sorry.

ST

Posting your actual code always helps when trying to solve particular problems - its easy for mistakes and errors to creep into code that hasn't been tested, and that might change the response you get.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:30AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month