I need to get this program to display the most expensive value and the most taxed value in text form from the names stored in the array. The following code works out everything apart from displaying the most expensive and most taxed items on the screen. This needs to be done by using if statements. This is using MS Visual Studio using Gwin.

#include "stdafx.h"
#include "gwin.h"
const int MAXITEMS=10;
const int MAXCHARS=30;
char Goods[MAXITEMS][MAXCHARS] = {"StrawberryJam", "Butter", "DVDPlayer", "ChildShoes",
"MP3Player", "Champagne", "WhiteBread", "ChanelNo5", "Shirt", "Kettle"};
int Category[MAXITEMS]={1,1,2,4,2,3,1,3,4,2};
double Price[MAXITEMS]={0.89,0.75,19.2,35.0,14.5, 24.5, 0.95, 30.5, 17.0, 19.2};




int main()
{
	double MostExpensive=0, MostTaxed=0;
	int i;
	int name;
	double ivat;
	double vat;
	double vati;
	double fc;
	double svat;
	double tvat;
	int TextValue;
	
	GWindow Gwin;
	
	// Clear the Gwin window
	Gwin.clear();
	
	
	Gwin.setPenColour(BLACK);
	Gwin.writeText(10,10,"Name");
	Gwin.writeText(150,10,"VAT");
	Gwin.writeText(260,10,"Final Cost");
	Gwin.writeText(10,270,"Most expensive item is");
	Gwin.writeText(10,300,"Most tax charged on");

	for(i=0; i<MAXITEMS; i++)
	{
		Gwin.setPenColour(BLACK);
		Gwin.writeText(10,i*20+50,Goods[i]);
		
		
		if (Category[i]==1)
		{
			ivat=Price[i]/10;
			svat=ivat/2;
			vat=ivat+svat;
			Gwin.writeDouble(150,i*20+50,vat);
			
			
			

		}
		if(Category[i]==2)
		{
			ivat=Price[i]/10;
			svat=ivat/2;
			tvat=svat/2;
			vat=ivat+svat+tvat;
			Gwin.writeDouble(150,i*20+50,vat);
			
			
		}
		if(Category[i]==3)
		{
			ivat=Price[i]/10;
			svat=ivat*2;
			tvat=ivat/2;
			vat=svat+tvat;
			Gwin.writeDouble(150,i*20+50,vat);
			
			
		}
		if (Category[i]==4)
		{
			ivat=Price[i]/10;
			svat=ivat/2;
			vat=ivat+svat;
			Gwin.writeDouble(150,i*20+50,vat);
			
		}
		
		fc=Price[i]+vat;
		Gwin.writeDouble(250,i*20+50,fc);
			if (fc>MostExpensive)
			{
			
				MostExpensive=fc;
				
			}
			if(vat > MostTaxed)
			{
				
				MostTaxed=vat;
				
			}
			
			

	}

	Gwin.writeDouble(200,270,TextValue);
	
	
	

	// Finally, wait for a key to be pressed
	Keyboard.waitKey();
	
	return 0;
}

Welcome to Daniweb!

- Please use code tags when you post code. It makes it much more readable for other uses.

- Please try to make the example as simple as possible to demonstrate the problem you're having. For example, in this case the drawing to the screen is taking up a significant portion of the code, and has nothing to do with the problem at hand. Then provide sample input, your current output, and your expected output to this small problem. It is a classic case of "help us help you"!

- PLEASE try not to use global variables. It is almost always a bad idea!

- Consider using 'else if' instead of a bunch of independent if statements on the same condition. I hear it's faster. You could also try a swtich() statement.

Please consider these things and post what you come up with!

Good luck,

Dave

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.