Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Reversed Name Challenge (Medium)

Here are some projects of actual programs you can practice making.

Reversed Name Challenge (Medium)

Postby FlawedLogic on Sun May 10, 2009 3:53 am

Prompt the user to input there name then output there name in reverse order.
FlawedLogic
 
Posts: 12
Joined: Sun May 10, 2009 3:08 am

Re: Reversed Name Challenge (Medium)

Postby lnmul on Wed May 20, 2009 5:18 pm

Why hello thar.
Code: Select all
#include <iostream>
using namespace std;

int main(){
   char line[100];
   for (int y = 0; y <= 99; y++)
      line[y] = '%';
   cout << "Enter a line of text up to 100 characters. End it with a percent sign (%).\n";
   cin.getline(line, 100, '%');
   cout << "Here is your line: ";
   cout << line << endl;
   cout << "Now here is your line in reverse: ";
   for (int x = 99; x >= 0; x--)
   {
      if (line[x] != '%')
         cout << line[x];
   }
   cout << endl;
   system("PAUSE");
   return 0;
}

Works with any line of text up to 100 chars. May increase the max later.
*EDIT* Had to change last line of code so it would work as an independent .exe file without Visual Studio.
lnmul
 
Posts: 2
Joined: Wed May 20, 2009 5:15 pm

Re: Reversed Name Challenge (Medium)

Postby HippyEwan on Fri May 22, 2009 8:24 am

Here's mine :)

Code: Select all
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string name;
    cout << "Enter your name: ";
    getline(cin,name);
    cout << "\nHere is your name in reverse: ";
    int i = name.length();
    while (i >= 0)
    {
        printf("%c", name[i]);
        i--;
    }
    cout << "\n\nHit any key to quit.\n\n";
    cin.ignore();
    return 0;
}
HippyEwan
 
Posts: 4
Joined: Sun Mar 29, 2009 1:10 pm

Re: Reversed Name Challenge (Medium)

Postby burgert on Thu Jun 11, 2009 8:55 am

heres mine

Code: Select all
#include <iostream>

using namespace std;

int main()
{
    string name;

    cout << "please enter your name" << endl;
    cin >> name;

    for (int i = name.size();i >= 0;i--)
    {
        cout << name[i];
    }
   
}

burgert
 
Posts: 4
Joined: Wed Jun 10, 2009 7:04 pm

Re: Reversed Name Challenge (Medium)

Postby DerHenker on Fri Jun 19, 2009 10:59 am

Hmm now that i have seen how others have done this im not sure if what i did is right ^^

It does the work dont look very pretty but it does the work, as long as your name is not longer then 10 letters :P

Code: Select all
#include "stdafx.h"
#include <iostream>

using namespace std;

int main(){

   cout<<"Hi what is your name?\n";
   cout<<"Type your name letter by letter after each letter press enter\n";
   cout<<"When your done press - and enter till you get your result\n";
   
   char a,b,c,d,e,f,g,h,i,j;

   cin>>a;
   cin>>b;
   cin>>c;
   cin>>d;
   cin>>e;
   cin>>f;
   cin>>g;
   cin>>h;
   cin>>i;
   cin>>j;

   cout<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j;
   cout<<"Sounds for me like: ";
   cout<<j<<i<<h<<g<<f<<e<<d<<c<<b<<a<<endl;
   
system("PAUSE");
return 0;
}


But i must admit that i had not any knowlege of how to turn a string around or reverse it :P
DerHenker
 
Posts: 11
Joined: Fri May 15, 2009 3:54 am

Re: Reversed Name Challenge (Medium)

Postby Jack Sparrow on Mon Sep 07, 2009 1:03 pm

Here's what I did:
Code: Select all
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
   cout <<"First Name: ";
   char name[10];
   cin >> name;
   for(int x = strlen(name); x >= 0; x--)
   {
      cout << name[x];
   }
      
   system("pause");
   return 0;
}
Jack Sparrow
 
Posts: 4
Joined: Mon Sep 07, 2009 12:53 pm

Re: Reversed Name Challenge (Medium)

Postby noobgrammer on Mon Sep 07, 2009 5:59 pm

Here you go make it a little more challenging have it check if it's a palindrome
(words say the same thing both ways like racecar, or two words like straw warts) get the idea
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando


Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests