Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 28th, 2005, 10:48 AM   #1
Magius Avvail
Newbie
 
Magius Avvail's Avatar
 
Join Date: Nov 2005
Posts: 23
Rep Power: 0 Magius Avvail is an unknown quantity at this point
Talking 'CIN' full sentences?

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

}
Magius Avvail is offline   Reply With Quote
Old Nov 28th, 2005, 11:06 AM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
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
Prm753 is offline   Reply With Quote
Old Nov 28th, 2005, 11:27 AM   #3
Magius Avvail
Newbie
 
Magius Avvail's Avatar
 
Join Date: Nov 2005
Posts: 23
Rep Power: 0 Magius Avvail is an unknown quantity at this point
Thanks man, that helps me out a lot .
Magius Avvail is offline   Reply With Quote
Old Nov 28th, 2005, 11:47 AM   #4
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
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:
Originally Posted by Mohamed Jihad
Durka durka!
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!
jayme is offline   Reply With Quote
Old Nov 28th, 2005, 12:04 PM   #5
Magius Avvail
Newbie
 
Magius Avvail's Avatar
 
Join Date: Nov 2005
Posts: 23
Rep Power: 0 Magius Avvail is an unknown quantity at this point
Quote:
Originally Posted by jayme
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 
}
My compiler doesn't seem to recognize any of the following:

#include <string.h>

#include <string>

or

#include <string>
using std::string;
Magius Avvail is offline   Reply With Quote
Old Nov 28th, 2005, 11:26 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by Magius Avvail
#include <IOSTREAM.H>
#include <IOMANIP.H>
#include <STDLIB.H>
#include <CONIO.H>
This isn't modern C++. These libraries are deprecated - it's not recommended you use them. You can find more info in the C++ FAQ.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 28th, 2005, 11:54 AM   #7
Magius Avvail
Newbie
 
Magius Avvail's Avatar
 
Join Date: Nov 2005
Posts: 23
Rep Power: 0 Magius Avvail is an unknown quantity at this point
Quote:
Originally Posted by Ooble
This isn't modern C++. These libraries are deprecated - it's not recommended you use them. You can find more info in the C++ FAQ.

I know, but I'm using an older version of Turb C++.
Also, I was brought up using the headers like that. *shrugs*
Magius Avvail is offline   Reply With Quote
Old Nov 28th, 2005, 12:07 PM   #8
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
what is wrong with this?

cin.get(myString,LengthOfString,'\n');
__________________
"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
Kilo is offline   Reply With Quote
Old Nov 28th, 2005, 12:09 PM   #9
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
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
Prm753 is offline   Reply With Quote
Old Nov 28th, 2005, 12:11 PM   #10
Magius Avvail
Newbie
 
Magius Avvail's Avatar
 
Join Date: Nov 2005
Posts: 23
Rep Power: 0 Magius Avvail is an unknown quantity at this point
Quote:
Originally Posted by Prm753
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.
I would, but the firewall behind this machine won't allow it. I'm on a computer at school, and I can't get anything better than Turbo C++. I have Dev C++ and Borland C++ at home, but here I'm stuck with Turbo C++.
Magius Avvail is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC