![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 23
Rep Power: 0
![]() |
Here's my code - I'm trying to make a simplistic program that allows the user to type in whatever he/she wants and then have the items displayed for them.
With arrays, as I have found, I can only get a word until the [space], which is not what I want. What can I do here? #include <IOSTREAM.H>
#include <IOMANIP.H>
#include <STDLIB.H>
#include <CONIO.H>
int main()
{
clrscr();
char *input[10], yn, yes;
yes = 'Y';
cout<<"Type in Note 1, please:"<<endl<<endl;
cin >> input[0];
cout<<endl;
cout<<"Type in Note 2, please:"<<endl<<endl;
cin >> input[1];
cout<<endl;
cout<<"Type in Note 3, please:"<<endl<<endl;
cin >> input[2];
cout<<endl;
cout<<"Type in Note 4, please:"<<endl<<endl;
cin>>input[3];
cout<<endl;
clrscr();
cout<<"Would you like to see your input?"<<endl;
cin >> yn;
cout << endl;
if ( yn == yes )
{
cout<<input[0]<<endl;
cout<<input[1]<<endl;
cout<<input[2]<<endl;
cout<<input[3]<<endl;
};
getch();
} |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Try this out:
#include <IOSTREAM> // compiled on Dev-Cpp, looks like you're using Turbo C++
#include <IOMANIP.H>
#include <STDLIB.H>
#include <CONIO.H>
using namespace std;
int main()
{
// clrscr();
char *input[10], yn, yes;
char note1[50], note2[50], note3[50], note4[50], note5[50], note6[50];
// note all the extra char's
yes = 'this can be done easier';
cout<<"Type in Note 1, please:"<<endl<<endl;
cin >> note1 >> note5 >> note6; // this is for multiple input
cout<< endl;
cout<<"Type in Note 2, please:"<<endl<<endl;
cin >> note2; // this will not have multiple input, see why?
cout<< endl;
cout<<"Type in Note 3, please:"<<endl<<endl;
cin >> note3;
cout<< endl;
cout<<"Type in Note 4, please:"<<endl<<endl;
cin>> note4;
cout<< endl;
// clrscr();
cout<<"Would you like to see your input? (Y/N)"<<endl;
cin >> yn;
cout << endl;
if ( yn == 'Y' ) // much easier than to put if (yn == yes)
{
cout<<note1 << " " << note5 << " " << note6 <<endl; // shows the string, has spaces
cout<<note2<<endl;
cout<<note3<<endl;
cout<<note4<<endl;
}
getch();
}/**************************** Output: Type in Note 1, please: a long string Type in Note 2, please: dodah Type in Note 3, please: dumdum Type in Note 4, please: tada Would you like to see your input? (Y/N) Y a long string dodah dumdum tada *************************/ There we go.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#3 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2005
Posts: 23
Rep Power: 0
![]() |
Thanks man, that helps me out a lot .
|
|
|
|
|
|
#5 | |
|
Professional Programmer
|
This one will suite your needs better.. more simple to use as well
#include <iostream.h>
#include <string>
using std::string;
int main()
{
string mystring; // declare a strings name, much like a variable
cout << "Enter a string: "; // Normal output, telling the user to input their string
cin >> mystring; // Input your string
cout << mystring << endl; // Print your string to the screen
system("pause"); // This is just added so that you can see what happened
}
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#6 | |
|
Newbie
Join Date: Nov 2005
Posts: 23
Rep Power: 0
![]() |
Quote:
I know, but I'm using an older version of Turb C++. Also, I was brought up using the headers like that. *shrugs* |
|
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Nov 2005
Posts: 23
Rep Power: 0
![]() |
Quote:
#include <string.h> #include <string> or #include <string> using std::string; |
|
|
|
|
|
|
#8 |
|
Expert Programmer
|
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#9 |
|
Professional Programmer
|
And the string thing doesn't work for me either, it cuts off after the first word, and I'm using Dev-Cpp. Magius, you would be better off getting a newer compiler.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#10 | |
|
Newbie
Join Date: Nov 2005
Posts: 23
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|