In: Computer Science
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main():
endProgram = 'no'
while endProgram == 'no':
# declare variables
notGreenCost = [0] * 12
goneGreenCost = [0] * 12
savings = [0] * 12
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
getNotGreen(notGreenCost, months)
getGoneGreen(goneGreenCost, months)
energySaved(notGreenCost, goneGreenCost, savings)
displayInfo(notGreenCost, goneGreenCost, savings, months)
endProgram = raw_input('Do you want to end program? (Enter no or yes): ')
while not (endProgram == 'yes' or endProgram == 'no'):
print 'Please enter a yes or no'
endProgram = raw_input('Do you want to end program? (Enter no or yes): ')
def getNotGreen(notGreenCost, months):
counter = 0
while counter < 12:
print 'Enter NOT GREEN energy costs for', months[counter]
notGreenCost[counter] = input('Enter now -->')
counter = counter + 1
print '-------------------------------------------------'
def getGoneGreen(goneGreenCost, months):
counter = 0
while counter < 12:
print 'Enter GONE GREEN energy costs for', months[counter]
goneGreenCost[counter] = input('Enter now -->')
counter = counter + 1
print '-------------------------------------------------'
def energySaved(notGreenCost, goneGreenCost, savings):
counter = 0
while counter < 12:
savings[counter] = notGreenCost[counter] - goneGreenCost[counter]
counter = counter + 1
def displayInfo(notGreenCost, goneGreenCost, savings, months):
counter = 0
print ' SAVINGS '
print '_____________________________________________________'
print 'SAVINGS NOT GREEN GONE GREEN MONTH'
print '_____________________________________________________'
while counter < 12:
print '$', savings[counter], ' $', notGreenCost[counter], ' $', goneGreenCost[counter], ' ', months[counter]
counter = counter + 1
main()
// C++ code
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
void getNotGreen(int notGreenCost[], string months[])
{
int counter = 0;
while (counter < 12)
{
cout << "Enter NOT GREEN energy costs for " <<
months[counter] << endl;
cout << "Enter now --> ";
cin >> notGreenCost[counter];
counter = counter + 1;
}
cout <<
"-------------------------------------------------\n";
}
void getGoneGreen(int goneGreenCost[], string months[])
{
int counter = 0;
while (counter < 12)
{
cout << "Enter GONE GREEN energy costs for " <<
months[counter] << endl;
cout << "Enter now --> ";
cin >> goneGreenCost[counter];
counter = counter + 1;
}
cout <<
"-------------------------------------------------\n";
}
void energySaved(int notGreenCost[],int goneGreenCost[], int
savings[])
{
int counter = 0;
while (counter < 12)
{
savings[counter] = notGreenCost[counter] -
goneGreenCost[counter];
counter = counter + 1;
}
}
void displayInfo(int notGreenCost[], int goneGreenCost[], int
savings[] , string months[])
{
int counter = 0;
cout << "\n";
cout << " SAVINGS \n";
cout <<
"_____________________________________________________\n";
cout << "SAVINGS NOT GREEN GONE GREEN MONTH\n";
cout <<
"_____________________________________________________\n";
while (counter < 12)
{
cout << "\n";
cout << "$" << savings[counter] << " $" <<
notGreenCost[counter] << " $" << goneGreenCost[counter]
<< " " << months[counter];
counter = counter + 1;
}
cout << endl;
}
int main()
{
string endprogram = "no";
while(endprogram == "no")
{
int notGreenCost[12] = {0};
int goneGreenCost[12] = {0};
int savings[12] = {0};
string months[12] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December"};
getNotGreen(notGreenCost, months);
getGoneGreen(goneGreenCost, months);
energySaved(notGreenCost, goneGreenCost, savings);
displayInfo(notGreenCost, goneGreenCost, savings, months);
cout << "Do you want to end program? (Enter no or yes):
";
cin >> endprogram;
while(endprogram != "yes" || endprogram != "no")
{
cout << "Please enter a yes or no\n";
cout << "Do you want to end program? (Enter no or yes):
";
cin >> endprogram;
}
}
}
/*
output:
Enter NOT GREEN energy costs for January
Enter now --> 12
Enter NOT GREEN energy costs for February
Enter now --> 23
Enter NOT GREEN energy costs for March
Enter now --> 32
Enter NOT GREEN energy costs for April
Enter now --> 11
Enter NOT GREEN energy costs for May
Enter now --> 22
Enter NOT GREEN energy costs for June
Enter now --> 12
Enter NOT GREEN energy costs for July
Enter now --> 11
Enter NOT GREEN energy costs for August
Enter now --> 45
Enter NOT GREEN energy costs for September
Enter now --> 33
Enter NOT GREEN energy costs for October
Enter now --> 23
Enter NOT GREEN energy costs for November
Enter now --> 22
Enter NOT GREEN energy costs for December
Enter now --> 12
-------------------------------------------------
Enter GONE GREEN energy costs for January
Enter now --> 23
Enter GONE GREEN energy costs for February
Enter now --> 32
Enter GONE GREEN energy costs for March
Enter now --> 11
Enter GONE GREEN energy costs for April
Enter now --> 10
Enter GONE GREEN energy costs for May
Enter now --> 12
Enter GONE GREEN energy costs for June
Enter now --> 34
Enter GONE GREEN energy costs for July
Enter now --> 54
Enter GONE GREEN energy costs for August
Enter now --> 33
Enter GONE GREEN energy costs for September
Enter now --> 22
Enter GONE GREEN energy costs for October
Enter now --> 21
Enter GONE GREEN energy costs for November
Enter now --> 12
Enter GONE GREEN energy costs for December
Enter now --> 10
-------------------------------------------------
SAVINGS
_____________________________________________________
SAVINGS NOT GREEN GONE GREEN MONTH
_____________________________________________________
$-11 $12 $23 January
$-9 $23 $32 February
$21 $32 $11 March
$1 $11 $10 April
$10 $22 $12 May
$-22 $12 $34 June
$-43 $11 $54 July
$12 $45 $33 August
$11 $33 $22 September
$2 $23 $21 October
$10 $22 $12 November
$2 $12 $10 December
Do you want to end program? (Enter no or yes): not
Please enter a yes or no
Do you want to end program? (Enter no or yes): yes
*/