View Full Version : Problems when trying to input a name to a program.

05-25-2002, 08:48 AM
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.

05-25-2002, 11:20 AM

> 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 )

The Dog
06-01-2002, 08:05 AM
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.

06-03-2002, 03:58 PM
How do you get easily readable source code from Visual C++?