| | |
Completely new to C++ and have question about using char
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2003
Posts: 1
Reputation:
Solved Threads: 0
Hello all, I will start off by saying Im in the dark with some aspects of C++, in an intro computer course at college. My question is about how to use char commands for when I have multiple users using the same segment of C++.
ex.
3 users are asked to enter their height etc..... Im not sure how to go about the it for 3, 1 user is easy and I have no problem.
Any thoughts or how to's would be appreciated
Thanks
Pete
ex.
3 users are asked to enter their height etc..... Im not sure how to go about the it for 3, 1 user is easy and I have no problem.
Any thoughts or how to's would be appreciated
Thanks
Pete
•
•
Join Date: Nov 2003
Posts: 4
Reputation:
Solved Threads: 0
use an array for your place holder. try doing it like this:
char height[] = new char[3];
this tells char that you are making an array. now, to access this you would do something like this, say to output in the dos-type command prompt of most beggining c++ classes
cout << "Height of 1 is: " << height[0];
the last space in the array is always NULL or \0. they are the same thing. now to just go through the array and print all of them you would do this:
for(i = 0; i < 3; i++){
cout << "Height of " << i << " is: " << height[i];
}
this would print everything in the array except the last byte which is NULL or \0. later one you will get to dynamic arrays which will be set to \0 or NULL before you start using them. But that is beside the point.
char height[] = new char[3];
this tells char that you are making an array. now, to access this you would do something like this, say to output in the dos-type command prompt of most beggining c++ classes
cout << "Height of 1 is: " << height[0];
the last space in the array is always NULL or \0. they are the same thing. now to just go through the array and print all of them you would do this:
for(i = 0; i < 3; i++){
cout << "Height of " << i << " is: " << height[i];
}
this would print everything in the array except the last byte which is NULL or \0. later one you will get to dynamic arrays which will be set to \0 or NULL before you start using them. But that is beside the point.
•
•
Join Date: Sep 2003
Posts: 22
Reputation:
Solved Threads: 0
What do you mean 3 users using your program? You're only going to have 1 user to your program, unless it's internet based.
If ya' mean 3 different inputs to teh program:
Change #define users 3 to #define users x, where x is the number of users your want.
Or something...
If ya' mean 3 different inputs to teh program:
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #define users 3 int main(void) { printf("Input %d heights:",users); int loop = 0; double temp[users]; while (loop < users) { scanf("%f",&temp[loop]); loop++; } return 0; }
Change #define users 3 to #define users x, where x is the number of users your want.
Or something...
![]() |
Similar Threads
- Need Help - Python Question (Python)
- Basic Variables Question (Visual Basic 4 / 5 / 6)
- help understanding "char" data type (C++)
- help on char pointers (C)
Other Threads in the C++ Forum
- Previous Thread: The difference between functions and templates?
- Next Thread: Big Game need progrmmers
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





