what's wrong with it?Code:#include <iostream.h> int main() { for (char x) ( char x; cout<<" Please imput name."; cin>>x cout<<" Welcome,"<<char x; ) return 0 }
what's wrong with it?Code:#include <iostream.h> int main() { for (char x) ( char x; cout<<" Please imput name."; cin>>x cout<<" Welcome,"<<char x; ) return 0 }
The for loop, the brackets and a redeclaration.
What does your compiler complain about ?
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Could you change it to make it work or something?
The use of pre-standard headers is bad too.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
oh and it says something about backward_warning.h
Perhaps you could explain why you wanted to use a for loop here. Also, a char variable will only hold one character, so it won't be able to hold a name like you want it to. You will have to look into strings for that. When you go to cout a variable, you do not need to specify its type beforehand, just say the variable name.
Mark Loeser
http://www.halcy0n.com
wrong bracket usage
redeclaration
old headers
why a loop here???
Here is a simple code:
Code:#include <iostream> using namespace std; int main() { cout << "Please input your name: "; char string[256]; // string with max. 256 characters cin.getline(string,'\n'); cout << "\nWelcome " << string << endl; system("pause"); // to keep the window open return 0; }
Last edited by codingmaster; 06-01-2003 at 11:30 AM.
You might wanna #include <cstdlib> just to be safe with that system( ) call.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
well, this is going to sound very nooby, the fact is that when an aplication is done and the finaltext is being viewed it immediately shuts down, giving me no time to read it. Thats why I made a loop to let it start agin so I can read the text
That's what system( "pause" ); does. It waits for a keypress.
If you had just read the FAQ, you might have found something pertaining to your problem.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
I use "getch()" as a pause, "system("pause")" I heard isn't a good idea to do. (I heard system commands in general were a bad idea )
system() is bad because it's slow and non-portable. What it does is run whatever command it takes as its paramater as though you typed it into the shell (try typing "pause" into the shell to see for yourself). Since "pause" is only good on Windows (as far as I know), it's not portable to say system("pause").Originally posted by Nuke
I use "getch()" as a pause, "system("pause")" I heard isn't a good idea to do. (I heard system commands in general were a bad idea )
But AFAIK it's equally unportable (albeit quicker) to use getch() because that mainly exists in Windows environments. What I usually do is declare my own non-portable functions in a single header file and simply replace that file when I switch platforms. You could define a void myPause() function in the header. The Windows version could call getch() and other versions can do other things.
How about a portable solution?
Code:inline void wait_for_keypress() { std::cin.ignore(std::cin.rdbuf->in_avail() + 1); }
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I don't understand why you are using a for loop also. But isn't the problem : you forgot
i think that it ????????Code:cin >> x;
-- begin snip of error code --
#include <iostream.h>
int main()
{
for (char x)
/* for checks for a positive condition and it is getting 0
the proper syntax in a for loop is
for (int i = 0; i < 10; i++)
{
}
if your looking for a forever loop
for (1)
{
}
/*
(
char x; // this is a variable that is only one character. char is not string.
cout<<" Please imput name.";
cin>>x
cout<<" Welcome,"<<char x;
)
return 0
}
-- end snip --
-- begin snip of corrected code --
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
std::string MyString;
for(int i = 0; i <= 10; i++)
{
std::cout << "Please enter your name: ";
std::getline(std::cin, MyString);
std::cout << "Welcome " << MyString << std::endl;
}
return 0;
}
-- end snip --
Last edited by Phylter; 06-03-2003 at 11:15 AM.