943,335 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 9368
  • C++ RSS
Nov 2nd, 2003
0

Completely new to C++ and have question about using char

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PeteECU is offline Offline
1 posts
since Nov 2003
Nov 3rd, 2003
0

Re: Completely new to C++ and have question about using char

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ShadowBranch is offline Offline
4 posts
since Nov 2003
Nov 3rd, 2003
0

Re: Completely new to C++ and have question about using char

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:

C++ Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2. #define users 3
  3.  
  4. int main(void) {
  5. printf("Input %d heights:",users);
  6. int loop = 0;
  7. double temp[users];
  8. while (loop < users) {
  9. scanf("%f",&temp[loop]);
  10. loop++;
  11. }
  12. return 0;
  13. }

Change #define users 3 to #define users x, where x is the number of users your want.

Or something...
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Mike29936 is offline Offline
22 posts
since Sep 2003
Nov 4th, 2003
0

Re: Completely new to C++ and have question about using char

Oh no... a While Loop. Run!
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Dec 10th, 2003
0

Re: Completely new to C++ and have question about using char

paladine, I don't believe your code is in c++. It seems to me like the old structured c.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
sammy is offline Offline
14 posts
since Dec 2003
Dec 20th, 2003
0

Re: Completely new to C++ and have question about using char

Well, I prefer printf() to cout. If the guy wants, he can change printf() to cout, and scanf() to cin.

But they do the same thing, so it doesn't really matter.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Mike29936 is offline Offline
22 posts
since Sep 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: The difference between functions and templates?
Next Thread in C++ Forum Timeline: Big Game need progrmmers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC