hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Sat Feb 07, 2009 3:16 am Post subject: C++ halp |
|
|
I made this code. It works perfectly, but I think there's a better and more effective way to do this. Any ideas? Oh, what it does is make roman numerals and a weird name thingy.
| Code: |
// learning.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
string start();
string loop();
string end(string out);
void extra(string character, string past);
int co;
string out;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "enter your name!" << endl;
string name;
string top;
string middle = "* ";
string bottom;
int namesize;
int i;
getline(cin, name);
namesize = name.length();
for(i=0;i!=(namesize+4);i++){
top+= '*';
}
middle += name + " *";
bottom = top;
cout << top << newline << middle << newline << bottom <<newline;
cout << start() << endl;;
system("PAUSE");
}
string start() {
string s;
int i;
getline(cin,s);
for (i = 0; i!= s.size() ; i++) {
if (isdigit(s[i]) == 0){
cout << "DIS INCORRECTS! (not a number)"<<endl;
return NULL;
}
}
co = atoi(s.c_str());
s = loop();
return(s);
}
string loop() {
if (co >= 1000) {
out.insert(out.size(),"M");
co-= 1000;
loop();
}
if (co >= 500) {
if (co >= 900){
co -= 900;
extra("M","C");
}else{
out.insert(out.size(),"D");
co -= 500;
loop();
}
}
if (co >= 100) {
if (co >= 400){
co -= 400;
extra("D","C");
}else{
out.insert(out.size(),"C");
co -=100;
loop();
}
}
if (co >= 50) {
if (co >= 90){
co -= 90;
extra("C","X");
}else{
out.insert(out.size(),"L");
co -=50;
loop();
}
}
if (co >= 10){
if (co >= 40){
co -= 40;
extra("L","X");
}else{
out.insert(out.size(),"X");
co-=10;
loop();
}
}
if (co >= 5) {
if (co >= 9) {
co -= 9;
extra ("X","I");
}else{
out.insert(out.size(),"V");
co -=5;
loop();
}
}
if (co >= 1) {
out.insert(out.size(),"I");
co -=1;
loop();
}
return out;
}
void extra(string character, string past){
out.insert(out.size(), past);
out.insert(out.size(),character);
loop();
return;
}
|
_________________
|
|