you're reading...

Translating programs between Python and C++

Here is a simple program in python:

def main():
    fuzzy = 3
    buzzy = 6.5
    raw_input("press <Ret> to end program.")
    print "Goodbye!"

def catsages(age1, age2):
    cats = age1 + age2

def dogyears(age):
    if age < 0:
        print "Negative age?!?  Back to the future."
    elif age < 3 or age > 110:
        print "Frankly, I don't believe you."
        print "That is ", age*7, "in dog years."

And here is its translation into C++ code:

#include <iostream>
using namespace std;

void catsages(int age1, float age2);
void dogyears(float age);

int  main() {
  int fuzzy = 3;
  float buzzy = 6.5;
  cout <<  "press any letter key then <Ret> to end program.";
  char x;
  cin >> x;
  cout << "Goodbye!" << endl;
void catsages(int age1, float age2){
  float cats = age1 + age2;

void dogyears(float age)  {
  if (age < 0)
    cout <<  "Negative age?!?  Back to the future." << endl;
  else if (age < 3  ||  age > 110)
      cout << "Frankly, I don't believe you." << endl;
      cout << "That is "<<  age*7 << "in dog years." << endl;


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: