Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

C++ help please

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 05-21-02, 03:43 PM Thread Starter   #1
Chris
Member

 
Chris's Avatar 

Join Date: Sep 2001
Location: England, UK

10 Year Badge
 
C++ help please


im probably going to be posting here for c++ help over the next few days, as i have been given an assignment. My first question is how can i take a user input i.e there name and output it in the form of " hello ....."

__________________
Folding@Home Team32
Chris is offline   QUOTE Thanks
Old 05-21-02, 05:04 PM   #2
druidelder
Member

 
druidelder's Avatar 

Join Date: Feb 2002

 
cout >> "What is your name? ";

cin << strName;

cout >> "Hello, " >> strName >> endl;

Of course, you need the rest of the program too, but that should be what you're looking for. I haven't done c++ in a while and don't have my book handy.

__________________
Vote the Goat in 2012

Heatware under druidelder

*Disclaimer* I am only human and may make mistakes. Nothing I say is gold. Feel free to correct any misinformation I may spew.
druidelder is offline   QUOTE Thanks
Old 05-21-02, 05:19 PM Thread Starter   #3
Chris
Member

 
Chris's Avatar 

Join Date: Sep 2001
Location: England, UK

10 Year Badge
 
thanks thats just what i needed

__________________
Folding@Home Team32
Chris is offline   QUOTE Thanks
Old 05-21-02, 05:51 PM Thread Starter   #4
Chris
Member

 
Chris's Avatar 

Join Date: Sep 2001
Location: England, UK

10 Year Badge
 
dalm i have a problem when i run it i get the name as a decimal number here is the code i have done so far

#include <iostream.h>
#include <conio.h>
#include <math.h>

void main()

{
int name;
clrscr();
cout <<"Welcome to my guess the number game"<<endl;
cout <<"This program will guess the number you are thinking of"<<endl;
cout <<"Simply think of a number between 1 - 100 and answer the following questions"<<endl;
cout <<"To answer the questions simply types Yes or No"<<endl;


cout <<"Please enter your name"<<endl;
cin >>name;
cout <<"Hello"<<name<<endl;
cout <<"lets play"<<endl;

}

__________________
Folding@Home Team32
Chris is offline   QUOTE Thanks
Old 05-21-02, 06:00 PM   #5
XWRed1
Senior Member

 
XWRed1's Avatar 

Join Date: Oct 2001

 
Don't make name an int. Make it a string.
XWRed1 is offline   QUOTE Thanks
Old 05-21-02, 07:57 PM Thread Starter   #6
Chris
Member

 
Chris's Avatar 

Join Date: Sep 2001
Location: England, UK

10 Year Badge
 
how can i do this can u giv eme an example im quite new to c++ although i remember my lecturer say something about a string, i must not have been listening

__________________
Folding@Home Team32
Chris is offline   QUOTE Thanks
Old 05-21-02, 10:47 PM   #7
Visidex
Member

 
Visidex's Avatar 

Join Date: Jan 2002

 
char * name;
char name[];

Both would allow for size name.
Or you could use something like:

char name[15];

to allow for a name of 14 characters.

Then theres <string> which I don't know much about.
Visidex is offline   QUOTE Thanks
Old 05-21-02, 10:52 PM   #8
XWRed1
Senior Member

 
XWRed1's Avatar 

Join Date: Oct 2001

 
Well, I don't mean to be mean, but you started off saying this was homework... I suggest you try and pay attention in class, and use this forum for backup, rather than substitute this forum for the lectures.

Basically, the problem was you were trying to put character data into a variable of data type int, meaning the computer was expecting you to put numeric data in there.

Visidex covered the code.
XWRed1 is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 04:14 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?