My Program bypasses cin

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

My Program bypasses cin

Postby gibran » Fri Oct 29, 2010 12:51 am

The program executes the first "cin", but then by passes the next one. When i change the data type to a float
it works well but i want 'char' data type not float.
please HELP



#include <iostream>
using namespace std;


int main()
{
char momname, dadname;

cout<<"Enter your mom's name:";
cin>>momname;

cout<<"\nEnter your dad's name:";
cin>>dadname;
return 0;
}
gibran
 
Posts: 1
Joined: Fri Oct 29, 2010 12:42 am

Re: My Program bypasses cin

Postby BlackDeath » Sat Oct 30, 2010 5:07 am

"char" type represents a SINGLE char. What you want for storing names is a string, so you should also add #include <string> and change the type of momname and dadname variables from "char" to "string".
Stat rosa pristina nomine, nomina nuda tenemus.
User avatar
BlackDeath
 
Posts: 107
Joined: Wed Feb 09, 2005 12:35 pm
Location: Under the full moon

Re: My Program bypasses cin

Postby Darapisal » Mon Nov 01, 2010 9:18 am

"char" can only contain one character last. So if you want char can contain more than one characters, you
should declare your variable like this:

Code: Select all
char momname[20], dadname[20];
Darapisal
 
Posts: 2
Joined: Mon Nov 01, 2010 8:39 am


Return to Homeworks

Who is online

Users browsing this forum: No registered users and 0 guests