Html coding inside of VS 2012

I have a Final Project assignment that I am trying to complete ahead of time. The problem I am running into is how to call a Visual Studio 2012 C++ function inside the html code so that it will output the order cost of an item based on the quantity in a table. All of the code output creates a webpage receipt. Here is the code I have so far. I am not asking to have it solved but instead be pointed in the right direction.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <fstream>

using namespace std;


int main () 
{
	//**WRITING TO A FILE*****/
	ofstream myfile;  //my file is the C++ representative of the output file
	ofstream receipt_in_html;
	int duckcounter=10,dc=0;
	int greenteacounter=3;
	int eggrollcounter=0;
	int gyrocounter=1;
	int orangechickencounter=100;
	int duckcounter=10,greenteacounter=3,eggrollcounter=0,gyrocounter=1,orangechickencounter=100;
	double dc=0,gc=0,ec=0,gyc=0,oc=0;
	dc=duckcounter*15.99,gc=greenteacounter*15.99,ec=eggrollcounter*15.99,gyc=gyrocounter*15.99,oc=orangechickencounter*15.99;
	
	
	//Output to an HTML/Webpage file to generate a receipt!!!!
	
	receipt_in_html.open("receipt.html");
	if (receipt_in_html.is_open())
	{
		
		receipt_in_html << "<html>\n";
		receipt_in_html << "    <head>\n";
		receipt_in_html << "		<title>A Receipt for your Order: Thank you for your business!!</title>\n";
		receipt_in_html << "    </head>\n";
		receipt_in_html << "    <body style=\"color:#F2F5A9; background-color:#08088A\">\n";        
		receipt_in_html << "	<p align=\"center\" style=\"color:#F2F5A9; background-color:#08088A\">\n";    
		receipt_in_html << "  </p>\n";
		receipt_in_html << "   <center>\n";
		receipt_in_html << "          <h1>RECEIPT</h1>\n";
		receipt_in_html << "		    <h2> Thank you for your Business</h2>\n";
		receipt_in_html << "           <p> \n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "				<img src=\"*.png\" width=\"200\" height=\"85\" alt=\"\"/>\n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "				<img src=\"*.jpg\" width=\"175\" height=\"200\" alt=\"\"/>\n";
		receipt_in_html << "			</p>\n";
		receipt_in_html << "			</p>\n";
		receipt_in_html << "			<p>\n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "          </p>\n";
		receipt_in_html << "	</center>\n";
		receipt_in_html << "			  <table border=\"1\" width=\"80%\" align=\"center\">\n";
		receipt_in_html << "				<tr>\n";
		receipt_in_html << "					<th>Item Number</th>\n";
		receipt_in_html << "					<th>Ordered</th>\n";
		receipt_in_html << "					<th>Quantity</th>\n";
		receipt_in_html << "					<th>Name</th>\n";
		receipt_in_html << "					<th>Cost</th>\n";
		receipt_in_html << "				</tr>\n";
		if(duckcounter>=1)
		{
			receipt_in_html << "				<tr>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\">1</td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=checkbox></td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=text name=Quantity></td>\n";
			receipt_in_html << "					<td width=\"10%\" align=\"center\"> Duck </td>\n";
			receipt_in_html << "					<td> 15.99 </td>\n";
			receipt_in_html << "				</tr>\n";
		}
		if(greenteacounter>=1)
		{
			receipt_in_html << "				<tr>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\">2</td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=checkbox></td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=text name=Quantity></td>\n";
			receipt_in_html << "					<td width=\"10%\" align=\"center\">Green Tea</td>\n";
			receipt_in_html << "					<td>$Priceless</td>\n";
			receipt_in_html << "				</tr>\n";
		}
		if(eggrollcounter>=1)
		{
			receipt_in_html << "				<tr>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\">3</td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=checkbox></td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=text name=Quantity></td>\n";
			receipt_in_html << "					<td width=\"10%\" align=\"center\">Egg Roll</td>\n";
			receipt_in_html << "					<td>$15.99</td>\n";
			receipt_in_html << "				</tr>\n";
		}
		if(gyrocounter>=1)
		{
			receipt_in_html << "				<tr>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\">4</td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=checkbox></td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=text name=Quantity></td>\n";
			receipt_in_html << "					<td width=\"10%\" align=\"center\">Gyro</td>\n";
			receipt_in_html << "					<td>$15.99</td>\n";
			receipt_in_html << "				</tr>\n";
		}
		if(orangechickencounter>=1)
		{
			receipt_in_html << "				<tr>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\">5</td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=checkbox></td>\n";
			receipt_in_html << "					<td width=\"05%\" align=\"center\"><input type=text name=Quantity></td>\n";
			receipt_in_html << "					<td width=\"10%\" align=\"center\">Orange Chicken</td>\n";
			receipt_in_html << "					<td>$15.99</td>\n";
			receipt_in_html << "				</tr>\n";
		}
		receipt_in_html << "			</table>\n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "				<br/>\n";
		receipt_in_html << "	</body>\n";
		receipt_in_html << "</html> \n";
		receipt_in_html.close();
		cout << "\n Receipt Generated: Double-click receipt.html in your folder!!!!" << endl;
		system("receipt.html");//open the reciept
    }
    else
    {
		cout << "\nThere was an error generating a receipt"<< endl;
	}
	system("pause");
	return 0;
}
closed account (o3hC5Di1)
Hi there,

A receipt should summary of an actual order, it only serves as output. You don't need to call any C++ functions from within the HTML. The only way to do so would be to have a (web)server installed which you could communicate with through a (asyncronous) HTTP GET or POST. On microsoft platforms, using C++ or C#, this is usually done using ASP.NET (active server pages).

Anyway, a receipt is not an order-form where the user enters data, submits it and then gets a receipt. It only serves as a summary for the data you have available within the C++ program.

If you mean to say that you want to insert the result of a calculation into the recept_in_html string, you can use simple concatenation:

receipt_in_html << "<td id=\"total\">" << calculate_total() << "</td>";

Hope that helps, please do let us know if you have any further questions.

All the best,
NwN
Thank you very much for your assistance. Exactly what I was looking to try and do.
Topic archived. No new replies allowed.