Thread: Problems when trying to input a name to a program.

  1. #1
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002

    Angry Problems when trying to input a name to a program.

    Hi! I have a problem when I am trying to set the rules and trying to let the program break out of the loop (only if succesful).

    And here's my code:

        Using Visual C++ 6  Service Pack 5
        by Grayson Peddie
        myfirstapp.cpp	Dated: 5/25/02
    #include <iostream>		// cout and cin definitions
    #include <string>			// I might think that this file contains getline...?
    using namespace std;		// For use with std:: namespace
    void name_squall(void)		// Implemented a name_squall function
        char max_squall_char = 13;		// max_squall_char has a charactor array of 14
        char squall(max_squall_char);	// assigned squall to max_squall_char
    								    // for a maximin of 12 charactors
        char *psquall[13];				// psquall is a pointer to a type char with
    									// a maximin of 13 charactors
        *psquall = &squall;				// psquall is a pointer to squall
            do							// Start a loop
    		// Output a text to a screen
    			cout<<"Enter a name for a charactor:\n\n"
    				<<"Names should not be longer than 12.\n"
    				<<"\tDefault: Squall \n\n";
    			// This is a string with a pointer from squall,
    			// Next is an array of max_squall_char and the last is escape code
    			// which drops down to a next line. I enclosed those with "( )".
    			cin.getline(&squall, max_squall_char, '\n');
    			// Here's what I have trouble with:
    				The rules are:
    					If I entered too many charactors, then I will get an error.
    					If I entered less than 12, then I may proceed out of a function
    					  but I couldn't get through!
    					If I don't enter any charactors, then I also get an error.
    				I'm not talking about compiler errors.
    			if(*psquall >= &squall && squall++)
    				cout<<"Error!" << endl << endl
    					<<"\tCan't enter a name longer than 12 charactors.";
    			if(*psquall < &squall && squall--)
    				cout<<"You named a charactor "<<*psquall
    			// This is where the code comes in when I forgot to enter charactors.
    			if (" ")
    		while(*psquall <= &squall);		// Yet that loop tells the program to go
    						                                // from the beginning, regardless if I
    									// set the <= or >= operator.
    void main(void)
    	int input_n;
    		// Well, it could skip the "cin" part...
    		cout<<"Are you ready to continue? 1 or 2 ";
    		// ...which didn't work because the program doesn't tell me to enter 1 for
    		// yes or 2 for no.
    		if (input_n=1)
    		if (input_n=2)
    I've commented everything to help you understand what has happened to me.

    Any suggestions?

    And by the way, sorry to make a mess, but VC++ uses IntelliSense Technology by Microsoft. So you just have to go with it so.
    Last edited by Grayson_Peddie; 05-25-2002 at 08:57 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe

    > char squall(max_squall_char);
    Should be
    char squall[max_squall_char];

    Then delete all that psquall stuff, it's just confusing the issue.

    > if (input_n=1)
    And this should be
    if ( input_n == 1 )

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Cape Town
    If the code that you posted is exactly the same as your program,
    then you oviously don't understand enough about 'C' programming to be writing such a program.

    Get a book on 'C' and read it. work your way through the book by running the listings they give you. Once you feel comfortable with the language, then go ahead and try anything you like.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    How do you get easily readable source code from Visual C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program that requests input of an integer number
    By theejuice in forum C Programming
    Replies: 6
    Last Post: 04-30-2008, 02:18 AM
  2. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 09:12 PM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. completed a program; desire input
    By spirited in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2003, 08:50 AM