Input Names

This is a discussion on Input Names within the C++ Programming forums, part of the General Programming Boards category; I can't input the names i need. I declared as a char nam[34]; and after the first name the program ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    54

    Input Names

    I can't input the names i need. I declared as a char nam[34];
    and after the first name the program terminates.
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <iomanip.h>
    
    int main()
    {
    	// declare variables
    	int hold;
    	int passenger;
    	char nam[34];
    	int smoke;
    	
    	// get input
    	for (passenger = 0; passenger <=20; passenger++)
    	{
    		cout << "Enter your name : ";
    		cin  >> nam[34];
    		cout << "Smoking on plane 1)Yes or 2) No" << endl;
    		cout << "Make a choice :";
    		cin  >> smoke;
    	}
    	
    	// switch statement
    	switch (smoke)
    	{
    		case 1:
    		cout << "Please sit in back of the plane on seats 15-20 " << endl;
    		break;
    		case 2:
    		cout << "Please sit on seats 1-14 and please don't smoke." << endl;
    		break;
    		default:
    		cout << "Seats are filled. Sorry." << endl;
    		break;
    	}
    	
    	// print boarding tickets
    	
    	
    	
    	cin >> hold;
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    119

    Re: Input Names

    You also need to include your switch statement inside the for loop if you want it to output the seat assignments for all 20 passengers

    -Futura
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  3. #3
    Neoseeker's master master2000's Avatar
    Join Date
    Dec 2002
    Posts
    101
    try

    Code:
    void main ()
    
    int hold, passenger, smoke ;
    char nam [34] ;
    and for the loop try

    Code:
    void main ()
    
    start:
     
    //code
    
    goto start;

  4. #4
    RPW
    RPW is offline
    Registered User
    Join Date
    Dec 2002
    Posts
    43

    Post Try this

    try this code:

    Code:
    #include <iostream.h>
    #include <string.h>
    #include <winbgim.h>
    void Seat ();
    void Name ();
    // declare variables
    	int hold;
    	int passenger;
    	char nam[50];
        int smoke;
    int main()
    {
    	
    	// get input
    	for (passenger = 0; passenger <=20; passenger++)
    	{
    		Name();
    		cout << "Smoking on plane 1)Yes or 2) No\n";
    		cin  >> smoke;
     	    Seat();
        }
    	while(!kbhit());
    	return 0;
    }
    
    void Seat(){
    	switch (smoke)
    	{
    		
      case 1:
    		cout << "Please sit in back of the plane on seats 15-20 \n";
    		while(!kbhit());
            break;
    		
      case 2:
    		cout << "Please sit on seats 1-14 and please don't smoke.\n";
    		while(!kbhit());
            break;
    		
      default:
    		cout << "Seats are filled. Sorry.\n";
    		while(!kbhit());
            break;
       }
    smoke =0;
    }
    
    void Name()
    {
      cout << "Plz, enter your name and remember to put a * at the end of your name :\n ";
      cin.getline(nam,50,'*'); //arry(nam),length(50),exit character(enter)
    }

    ill attach the winbgim.h file for u
    Attached Files Attached Files

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    @master2000
    There are stacks of posts on here saying what's wrong with void main and goto, I suggest you do a search and read a few before posting answers like that.

    @RPW
    Don't use no standard function calls when answering posts on here. The OP's compiler probably hasn't heard of winbgim.h and kbhit(). I suggest you read this.

    @sonict
    Your code, if fixed as Salem suggests, will work, but will only allow you to store one person. You need to think 2-d arrays, or better still an array of structures to complete this task.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  4. Problem with File Input & Pointers
    By jenna in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 11:34 PM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21