help writing program to add prices of components.

0 alejandro macias · June 9, 2015
Can anyone steer me in the right direction, so basically I have to write a program for building a computer.  I have to keep it limited to 3 components i.e Hard drive, monitor, CPU.  of those 3 components they have 3 different options i.e Hard drive 500gb, 1TB, 2TB.  The user picks one of each of those upgrades and the program is supposed to add up those 3 prices of the components + baseline computer cost + sales tax = total price. 

I am a beginner and my teacher did not really give any help for this type of coding, I just want to know where to start looking.  I know it may have to with a loop but I just want to be sure.


Post a Reply


Oldest  Newest  Rating
0 Zachary B · June 9, 2015
It sounds like the easiest way to do this is to have three variables ( hardDrvie, monitor, CPU) take the value of the variables using input/output

std::cout << "Please select the Hard Drive..." << std::endl; 
std::cout << "1.) 500 GB\n 2.)1TB\n 3.)2TB" << std::endl; 

std::cin >> hardDrive;

then use and if/switch statement to determine the value of the variable.

ex: if (hardDrive == 1)
hardDrive = 100;

do that for all variable. After collecting all the variables do something like 

totalCost =  hardDrvie + monitor + CPU + baseline computer cost + sales tax; 
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator