Mixed mode

I had an assignment for class and got it back and lost a few points for using mixed mode. I can't see where I have mixed mode so I was hoping some other eyes might help. Per my VS 2012 settings it should show me if I'm using mixed mode. Am I just blind or is my teacher wrong? I find it highly unlikely my teacher to be wrong so hoping to educate myself here. Thanks for any help. FYI this is an entry level programming with C++ class, so sorry if some of my coding seems crude, working with the tools I have been taught so far.

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
// ProgrammingProject1.cpp : Defines the entry point for the console application.
// Programming Project #1


#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	double NW_PC;
	double secondDrive;
	double camera;
	double software;
	double subTotal;
	double grandTotal;
	double totalTax;
	//NW_PC = 1498.23;
	//secondDrive = 84.00;
	//camera = 119.00;
	//software = 49.00;
	
	//data entry
	cout << "Enter total number of NW-PCs being purchased: ";
	cin >> NW_PC;
	cout << endl;
	cout << "Enter total number of Second Drives being purchased: ";
	cin >> secondDrive;
	cout << endl;
	cout << "Enter total number of Cameras being purchased: ";
	cin >> camera;
	cout << endl;
	cout << "Enter total number of Software Bundles being purchased: ";
	cin >> software;
	cout << endl;
	
	//receipt
	cout << right << setw(17) << "*********" << endl << endl; // beginning of receipt title
	cout << right << setw(21) << "NewWave Computers" << endl << endl;
	cout << right << setw(17) << "123 Main St" << endl;
	cout << right << setw(22) << "Somewhere MO 65555" << endl << endl; // end of receipt title
	cout << "QTY" << " Item" << right << setw(19) << "Cost" << endl << endl; //header of purchases

	//purchases
	cout << fixed << setprecision(0) << right << setw(2) << NW_PC << "  " << left << setw(19) << "NW-PC" << " $" << right << setw(9) << fixed << setprecision(2) << NW_PC * 1498.23 << endl << endl;
	cout << fixed << setprecision(0) << right << setw(2) << secondDrive << "  " << left << setw(19) << "Second Drive" << " $" << right << setw(9) << fixed << setprecision(2) << secondDrive * 84.00 << endl << endl;
	cout << fixed << setprecision(0) << right << setw(2) << camera << "  " << left << setw(19) << "Camera" << " $" << right << setw(9) << fixed << setprecision(2) << camera * 119.00 << endl << endl;
	cout << fixed << setprecision(0) << right << setw(2) << software << "  " << left << setw(19) << "Software Bundle" << " $" << right << setw(9) << fixed << setprecision(2) << software * 49.00 << endl << endl;
	cout << fixed << setprecision(0) << right << setw(34) << "----------" << endl << endl;
	
	//totalling
	subTotal = (NW_PC * 1498.23) + (secondDrive * 84.00) + (camera * 119.00) + (software * 49.00);
	cout << right << setw(25) << "Total $" << fixed << setprecision(2) << right << setw(9) << subTotal << endl << endl;
	totalTax = (subTotal / 100) * 7.65;
	cout << right << setw(25) << "Tax $" << fixed << setprecision(2) << right << setw(9) << totalTax << endl << endl;
	cout << right << setw(34) << "----------" << endl << endl;
	grandTotal = totalTax + subTotal;
	cout << right << setw(25) << "Grand Total $" << fixed << setprecision(2) << right << setw(9) << grandTotal << endl << endl;
	
	string junk;
	cout << "Enter any key to continue: " << endl;
	cin >> junk;

	return (0);
}

Last edited on
Can we first define what "mixed code" means? Because this is the first time I've seen that term.
There are a number of things about the code which could be improved. but the main one for me is the hard-coding of numbers such as 1498.23 in more than one place. This can be a real-world problem. What if the pricing changes? The programmer goes into the code, changes the price but it still uses the old value because it is scattered throughout the code and some were missed. Putting values like this in just a single place would be the primary problem to be fixed. (looking at some of the commented-out lines, it seems that idea was considered but not carried through).

Another issue is the use of type double for integer values. Where a value is clearly an integer - a whole number of cameras for example, then the variable should be an integer.

Use of floating-point can allow such nonsense as this:
Enter total number of NW-PCs being purchased: 3.14

Enter total number of Second Drives being purchased: 2.718

Enter total number of Cameras being purchased: 0.5

Enter total number of Software Bundles being purchased: 0.3333

        *********

    NewWave Computers

      123 Main St
    Somewhere MO 65555

QTY Item               Cost

 3  NW-PC               $  4704.44

 3  Second Drive        $   228.31

 0  Camera              $    59.50

 0  Software Bundle     $    16.33

                        ----------

                  Total $  5008.59

                    Tax $   383.16

                        ----------

            Grand Total $  5391.74

Enter any key to continue:



As for your teacher's concerns, I'm not sure, possibly it was a reference to line 57?
 
	totalTax = (subTotal / 100) * 7.65;

My first concern on reading this line was whether integer division was taking place. At line 18, the variable double subTotal; is declared. So the calculation will correctly do a floating-point division. But I suppose what your teacher was referring to was the use of double and int in the same expression. I would usually tend to write 100.0 and this is probably what your teacher wanted.
Last edited on
helios wrote:
Can we first define what "mixed code" means? Because this is the first time I've seen that term.

I second that. I don't know what it is referring to either.
Registered users can post here. Sign in or register to post.