-
int char and float
lets say i had a program saying
Code:
#include <iostream>
using namespace std;
int main()
{
float name;
float lastname;
cout<<"Enter first name"<<endl;
cin>>name;
cout<<"Enter last name"<<endl;
cin>>lastname;
cout<<"your first name is "<<name<<" and your second name is "<<lastname<<endl;
cin.get();
return 0;
}
why dosent that work?
-
Try using
char name[100];
or
string name;
You can't store "fred" in a float!!!
-
if you use strings (ie)
dont forget to include string.
Strings are very cool - you can concatenate them easily using +, and they resize themselves. Very awesome.
-
ok i kind of get what you mean can someone please convert my code to how it should be so i can work it out from that
-
Code:
#include <iostream>
#include <string>
int main()
{
std::string name;
std::string lastname;
cout << "Enter first name" << endl;
cin >> name;
cout << "Enter last name" << endl;
cin >> lastname;
cout << "your first name is " << name << " and your second name is " << lastname << endl;
cin.get();
return 0;
}
-
thanx so much:D you have just taught me how to use strings
-
remember to put in
Code:
using std::cout;
using std::cin;
using std::endl;
Better than using using namespace std;