You are viewing our Forum Archives. To view or take place in current topics click here.
Help with a simple program
Posted:

Help with a simple programPosted:

Taylor
  • Ultra Gifter
Status: Offline
Joined: Apr 30, 201410Year Member
Posts: 5,962
Reputation Power: 15122
Status: Offline
Joined: Apr 30, 201410Year Member
Posts: 5,962
Reputation Power: 15122
Hello everyone, this is my first time into this forum (Im very new to coding). Im taking a class at school for C++. I am currently working on a project for the class, and I am completely lost. I cannot figure out how to do it, at all. I would greatly appreciate some guidance from someone who knows more on the subject.

What I have to do is this:

I have to create a program that will get input from a user (using cin>>), all I have to get is the users first name, and then their last name.

After the program receives the information, the program needs to put in onto the output screen in REVERSE and first/last names are separated by a comma. I want the program to look something like this (in Execution):

Please insert FIRST name:
(user types in first name)

***New Screen***

Please insert LAST name;
(user types in last name)

***New Screen***

Hello,
(LAST NAME) , (FIRST NAME)


I have the program started, but I know I messed up in a few places, and like I mentioned, I am very new to C++ and just started using cin>> and just learned TODAY how to use strings.

Here is an example of what I started:

[ Register or Signin to view external links. ]


The program I am using is TCLite (If you even need to know that)

If someone would be able to make me an example, that would be amazing. And again, Im new to this kind of forum, but you all should hear from me soon with many more questions/concerns.

Whoever can get this done for me, I love you.
#2. Posted:
ip
  • Fairy Master
Status: Offline
Joined: Dec 30, 201212Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201212Year Member
Posts: 3,778
Reputation Power: 3016
Alright, since you're new I'll tell you that putting your string within a char array isn't always the best thing to do, just declare a string and make it equal to that. Here is some code to help you out:

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

using namespace std;

main()
{
   string fName, lName;
   
   cout << "Please enter your First Name: " << endl;
   cin >> fName;
   clrscr();
   cout << "Please enter your Last Name: " << endl;
   cin >> lName;
   cout << "Your name is: " << fName << " " << lName << endl;

   getch();
}
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.