There is C++ 98, and C++ 03, and now C++ 11 (and a handful of technical reports and recognised extensions and the like).
I'm guessing by 3.0 you're actually referring to some kind of IDE or compiler. Borland? Turbo C++? Some other ancient, horribly out-of-date compiler that can't handle any C++ conforming to one of the standards? I expect so. One day I'm going to track down the places teaching using these things and be very sarcastic at the staff.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
int main()
{
std::cout << "Enter name:";
std::string name;
std::cin >> name;
std::cout << "Enter age:";
int age;
std::cin >> age;
std::cout << std::endl;
std::cout << name << " is " << age << " years old.";
return 0;
}
This is correct C++ conforming to the C++ standards. I'd guess that it won't work with your compiler, though. Tell us what it complains about, and we can mash something together that your compiler will accept :)
I would have pointed the OP to the C++ tutorial in here. I would have told him what to look for in the tutorial and have him write the code himself. I too agree that it was way too easy for the OP. But Moschops is a regular here and knows the drill. I guess he had his reasons.
I forsaw a future... a future in which I had to hold the OP's hand through every keypress. To be unable to do such a (relatively) simple thing, and to not have the initiative to use google and find some example code and explanatory notes; these things imply that the approach of pointing the OP to example code was just going to end in tears.
Also, I really do suspect that the code I posted won't compile on his compiler :p
It wasn't a complicated example. If he has trouble with this and he decides to "steal" his answer, then perhaps he'll learn nothing and fail his class. We've had plenty of people beg this forum for help and I sadistically laugh. :D
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char name[]="";
int age;
cout<<"enter name :";
cin>>name;
cout<<"Enter Age :";
cin>>age;
cout<<"if name is "<<name<<" and age is "<<age<<endl;
cout<<" then '"<<name<<"' is "<<age<<" years old";
getch();
}