473,386 Members | 1,973 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,386 software developers and data experts.

cin, cout rows and columns

10
I don't know how do get the rows can you help me please :(

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int rows;
  7. int cols;
  8. string sym;
  9. int count;
  10.  
  11. cout << "Please enter a symbol to be display: ";
  12. cin >> sym;
  13.  
  14. do
  15. {
  16. cout << "\tPlease enter how many colunms to create: ";
  17. cin >> cols;
  18. cout << "\n\n\n";
  19. }
  20.  
  21. while(cols < 10);
  22.  
  23. for (count = 1; count <= cols; count++)
  24.  
  25. cout << "\n\t\t" << sym;
  26.  
  27. cin.ignore();
  28. return 0;
  29. }
Jun 3 '07 #1
10 11018
Savage
1,764 Expert 1GB
By using nested loops,do u know what nested loops are?

Savage
Jun 3 '07 #2
oi123
10
By using nested loops,do u know what nested loops are?

Savage
nested loop is a loop that inside another loop?, :( I'm so behind on this I can't figure out how to do this anymore and the program is due this Monday, my friend told me to do it as

Expand|Select|Wrap|Line Numbers
  1. for (int x=0; x<rows; x++)
  2. {
  3.   for (int y=0; y<cols; y++)
  4.   {
  5.     cout >> "enter character: ";
  6.     cin << sym;
  7.  
  8.   }
  9. }
but I just don't understand why he prompt user to input character after rows and column and how would it generate in to a map? I'm very confuse and so afraid to ask him again because he might get mad this time after so many question already ask lol.
Jun 3 '07 #3
Savage
1,764 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. for (int x=0; x<rows; x++)
  2. {
  3.   for (int y=0; y<cols; y++)
  4.   {
  5.     cout >> "enter character: ";
  6.     cin << sym;
  7.  
  8.   }
  9. }
Tell me something:

Are u suppossed to print one character,or more of them?

and please use codetags when posting ur code ;)
Savage
Jun 3 '07 #4
oi123
10
I'm suppose to create a floor plan of a room that contain a floor tiles, wall and entry door and a escape hatch, a key and a piranha and have at less 10 rows and 10 columns by prompting user to enter any symbol they desire, I just don't know what method I should use :(
Jun 3 '07 #5
Savage
1,764 Expert 1GB
I'm suppose to create a floor plan of a room that contain a floor tiles, wall and entry door and a escape hatch, a key and a piranha and have at less 10 rows and 10 columns by prompting user to enter any symbol they desire, I just don't know what method I should use :(
Do u know how it's supposed to look,were there a example in ur assigment?

Please be more specific and supply more information

Savage
Jun 3 '07 #6
oi123
10
Do u know how it's supposed to look,were there a example in ur assigment?

Please be more specific and supply more information

Savage

example

please enter a character for wall
cin >> w
please enter how many rows:
cin >> 10;
please enter how many columns:
cin >> 10;



so it create a map with 10 rows and columns

wwwwwwwwww
w w
w w
w w
w w
w w
w w
w w
w w
wwwwwwwwww
Jun 3 '07 #7
Savage
1,764 Expert 1GB
example

please enter a character for wall
cin >> w
please enter how many rows:
cin >> 10;
please enter how many columns:
cin >> 10;



so it create a map with 10 rows and columns

wwwwwwwwww
w w
w w
w w
w w
w w
w w
w w
w w
wwwwwwwwww
Ok here are some hints:

1.ask user to input a character.
2.create nested loops,so that counter from first loop tells u in which row u are and secound one is printing characters in row.
3.in nested loop check the counter from the first loop,if that value equals to 1 or to number of rows,print just symbol if not check the counter from the inner loop,if it has a value of 1 or of characters per row,print symbol else print whitespace.
4.close parenthisis for the inner loop,and add endl,or '\n' to move on to next row.

Savage
Jun 3 '07 #8
oi123
10
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     //string sym;
  8.     int x, y;
  9.     int rows;
  10.     int cols;
  11.     do
  12.     {
  13.     cout << "Please enter how many rows: ";
  14.     cin >> rows;
  15.     } while(rows <10);
  16.  
  17.     do
  18.     {
  19.         cout << "Please enter how many column: ";
  20.         cin >> cols;
  21.     } while (cols <10);
  22. for(int y =1; y <= rows; y++)
  23.  
  24.     cout << y << endl;
  25. for(int x =1; x <= cols; x++)
  26.     cout << x;
  27.  
  28. cin.ignore(); cin.ignore();
  29.   return 0;
  30. }
  31.  
okay this is all I have, now how do I prompt user to input for chracter to create row and column and an entrance also exit door. sorry I can't figure it out anymore :(
Jun 4 '07 #9
oi123
10
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.     int rows;
  10.     int cols;
  11.     char wall;
  12.     do
  13.     {
  14.     cout << "Please enter how many rows: ";
  15.     cin >> rows;
  16.     } while(rows <10);
  17.      string map[rows];
  18.     do
  19.     {
  20.         cout << "Please enter how many column: ";
  21.         cin >> cols;
  22.     } while (cols <10);
  23.     cout << "Please enter a rows for wall: ";
  24.     cin >> wall;
  25. for(int i=1; i< rows; i++)
  26. {   
  27. do
  28. {
  29.  
  30.     map[i] = string(getline()); 
  31. } while (map[i].length!=cols);
  32.  
  33. for (int i = 0; i < rows; i++)
  34.    for (int j = 0; j < cols; j++)
  35.         if (map[i][j] == wall) map[i][j] = ' ';
  36.  
  37.  
  38. }
  39. // for(int x =1; x <= cols; x++)
  40.    // cout << x;
  41.  
  42. cin.ignore(); cin.ignore();
  43.   return 0;
  44. }
  45.  

this is what I have so far but is keep giving me an error because of map size any idea why?
Jun 4 '07 #10
Savage
1,764 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.     int rows;
  10.     int cols;
  11.     char wall;
  12.     do
  13.     {
  14.     cout << "Please enter how many rows: ";
  15.     cin >> rows;
  16.     } while(rows <10);
  17.      string map[rows];
  18.     do
  19.     {
  20.         cout << "Please enter how many column: ";
  21.         cin >> cols;
  22.     } while (cols <10);
  23.     cout << "Please enter a rows for wall: ";
  24.     cin >> wall;
  25. for(int i=1; i< rows; i++)
  26. {   
  27. do
  28. {
  29.  
  30.     map[i] = string(getline()); 
  31. } while (map[i].length!=cols);
  32.  
  33. for (int i = 0; i < rows; i++)
  34.    for (int j = 0; j < cols; j++)
  35.         if (map[i][j] == wall) map[i][j] = ' ';
  36.  
  37.  
  38. }
  39. // for(int x =1; x <= cols; x++)
  40.    // cout << x;
  41.  
  42. cin.ignore(); cin.ignore();
  43.   return 0;
  44. }
  45.  

this is what I have so far but is keep giving me an error because of map size any idea why?
U are building array of strings and putting it on the stack:

string map[rows];

this is not correct,because rows is variable and stack can only support constant values,u need to allocate it dynamicly.

In c++ that is done with using new:

string *map/a pointer to a string called map

map=new map[rows] //allocating memory for map

now it can be used same way:

map[i],...

There are also more of the problems but we will diel with them later,first make sure to allocate memory for string map

Savage
Jun 4 '07 #11

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

Similar topics

3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
0
by: Ireneus Broncel | last post by:
I have a class which reads Groups and Users from ActiveDirectory. The Problem is, that i have about 10000 rows as product. When I am trying to read the "memberOf" Objects out of this field i get...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
0
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on...
7
by: lethek39 | last post by:
Hey I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
1
by: tucson | last post by:
I have a gridview that has a blank row with 2 input fields: file to upload, and a description of the file. They click Add and a new row is added, Remove and the row is removed. The problem is:...
2
by: Encrypted | last post by:
i am working with a matrix manipulation program...consists of a matrix class and its member functions.. i have also overloaded << and >>...so dat dey can read and print d whole matrix at one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.