how to do this in c++ 3.0

write a program in c++ to input name (first name only) and age and print the output as: if name is "jack" and age is 17, then Jack is 17 years old.


please help me i cant do this... please tell me how to do it
There is no such thing as C++ 3.0

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 :)
Last edited on
Way to just give him his whole homework assignment without any effort from him.
I'm banking on it not working with his compiler. :)
Way to just give him his whole homework assignment without any effort from him.


OP asks for help, OP gets it. Get over it.
I would've posted a reply very similar to Moschops'.
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
Just learning to actually learn is an important piece of programming, and I think that's where the fun is. Learning to do something yourself.
To some degree, I was also just having a bad day. Such things happen.
Lol, one does not apologize for helping someone who asked for help...
OP didn't want redirects but an actual answer, which you gave. Correct decision.
Actually, this forum is generally against just straight giving someone an answer who has not shown any effort towards figuring it out himself.
+1 ResidentBiscuit
thanx moschops
closed account (S6k9GNh0)
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();
}

i tried this and it worked
Last edited on
char name[]="";

That's the same as:
1
2
char name[1];
name[0] = '\0';

Topic archived. No new replies allowed.