how to move code from phyton to c++

closed account (Nh79E3v7)
Write your question here.
how i can move code from python to C++.....
1. You understand python syntax
2. You understand what the algorithm actually does
3. You understand C++ syntax
leads to:
4. You write C++ code that implements the same algorithm
closed account (Nh79E3v7)
i don't understand how to move a python to c++.....i have try it...but it can't to run because have many error....please help me....i can't do that...and i don't understand
Python and C++ are two different languages. To translate one language to another you need to have knowledge of both languages. It might not be as simple as just changing line by line, but could require bigger structural changes.
Last edited on
@ OP, post the python code and your C++ code and we can help you to understand. Without the code, it is hard to know what specific issues you are having.
closed account (Nh79E3v7)
my python code...i want to move from phyton to c++
print "Welcome To The Resistor Calculator"
print "Our Group Members\nMuhammad Harith Bin Kamlyzan\nMuhammad Hisyam Bin Harmizon\nIkhwan Hakim Bin Mohd Asri\nShahrul Izwan Bin Kamal Akhball\nMuhammad Shahzlan Bin Mohd Nizam"

start = raw_input("Press Enter To Start")

first_colours = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Purple","Grey","White"}
while True:
first_colour = raw_input("\nPlease State The First Colour Band\nBlack\nBrown\nRed\nOrange\nYellow\nGreen\nBlue\nPurple\nGrey\nWhite\nYour Choice?\n")

if first_colour == "Black":
first_colour = 0
break
elif first_colour == "Brown":
first_colour = 1
break
elif first_colour == "Red":
first_colour = 2
break
elif first_colour == "Orange":
first_colour = 3
break
elif first_colour == "Yellow":
first_colour = 4
break
elif first_colour == "Green":
first_colour = 5
break
elif first_colour == "Blue":
first_colour = 6
break
elif first_colour == "Purple":
first_colour = 7
break
elif first_colour == "Grey":
first_colour = 8
break
elif first_colour == "White":
first_colour = 9
break
else:
print "Invalid colour name"

second_colours = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Purple","Grey","White"}
while True:
second_colour = raw_input("\nPlease State The Second Colour Band\nBlack\nBrown\nRed\nOrange\nYellow\nGreen\nBlue\nPurple\nGrey\nWhite\nYour Choice?\n")

if second_colour == "Black":
second_colour = 0
break
elif second_colour == "Brown":
second_colour = 1
break
elif second_colour == "Red":
second_colour = 2
break
elif second_colour == "Orange":
second_colour = 3
break
elif second_colour == "Yellow":
second_colour = 4
break
elif second_colour == "Green":
second_colour = 5
break
elif second_colour == "Blue":
second_colour = 6
break
elif second_colour == "Purple":
second_colour = 7
break
elif second_colour == "Grey":
second_colour = 8
break
elif second_colour == "White":
second_colour = 9
break
else:
print "Invalid colour name"

third_colours = {"Black","Brown","Red","Orange","Yellow","Green","Blue","Purple","Grey","White"}
while True:
third_colour = raw_input("\nPlease State The Third Colour Band\nBlack\nBrown\nRed\nOrange\nYellow\nGreen\nBlue\nPurple\nGrey\nWhite\nYour Choice?\n")

if third_colour == "Black":
third_colour = 1
break
elif third_colour == "Brown":
third_colour = 10
break
elif third_colour == "Red":
third_colour = 100
break
elif third_colour == "Orange":
third_colour = 1000
break
elif third_colour == "Yellow":
third_colour = 10000
break
elif third_colour == "Green":
third_colour = 100000
break
elif third_colour == "Blue":
third_colour = 1000000
break
elif third_colour == "Purple":
third_colour = 10000000
break
elif third_colour == "Grey":
third_colour = 100000000
break
elif third_colour == "White":
third_colour = 1000000000
break
else:
print "Invalid colour name"

fourth_colours = {"Gold","Silver","None"}
while True:
fourth_colour = raw_input("\nPlease State The Fourth Colour Band\nGold\nSilver\nNone\nYour Choice?\n")

if fourth_colour == "Gold":
fourth_colour = 5
break
elif fourth_colour == "Silver":
fourth_colour = 10
break
elif fourth_colour == "None":
fourth_colour = 20
break
else:
print "Invalid colour name"

total = second_colour*third_colour
print "The Total Value Of Your Resistor Is : " + str(first_colour) + str(total) + " +-" + str(fourth_colour) + '%\n'
exitprogram = raw_input ("\nPress Enter To Exit")


closed account (Nh79E3v7)
please help me.....reply my chat
in your case, you define string array , you are using the == operator , in cpp you must specify the type when you declare a variable unless you are using the auto keyword. Even thought there might be ambiguity. The : would be replace by {} for its scope. At the end of every instruction you must have a ; for your raw_input use std::cout << "blabla"; and then put a string value; std::cin >> value; then you compare that value. There is more to say I am just pointing some here. Good luck. If you want my advise , write pseudocode to help you out.
closed account (Nh79E3v7)
i don't understand......please i can't think anymore
Writing the names of everyone who is asking people on he internet to do their homework for them ( Muhammad Harith Bin Kamlyzan, Muhammad Hisyam Bin Harmizon, Ikhwan Hakim Bin Mohd Asri, Shahrul Izwan Bin Kamal Akhball, Muhammad Shahzlan Bin Mohd Nizam ) probably isn't a great idea.
closed account (Nh79E3v7)
okeyy...fine...i don't ask anymore
closed account (Nh79E3v7)
bye..
Topic archived. No new replies allowed.