- #1

- 21

- 1

- Homework Statement
- I can not seem to get the correct calculations for when the user enters no for touchscreen--it always adds 60 to final calculation no matter what. any help will be appreciated.

- Relevant Equations
- Source code in the bottom.

C:

```
#include <iostream>
#include <string>
#include<iomanip>
//prototypes
double gettingInfo(double&, double&, double&, bool&, char&);
double errorChecking(double&);
double calculatingPrice(double&, double&, double&, bool&);
double printingReciept(double&, double&, double&,double&);
using namespace std;
int main()
{
cout<<"This program calculates the cost of a customized computer--given specifications.\n\n";
double speedOfProcessor;
double storageCapacity;
double ramAmount;
double total;
bool touchscreen;
char touchscreenCheck;
string yesOrNo;
gettingInfo(speedOfProcessor, storageCapacity, ramAmount, touchscreen, touchscreenCheck);
total=calculatingPrice(speedOfProcessor,storageCapacity, ramAmount,touchscreen);
printingReciept(speedOfProcessor, storageCapacity, ramAmount, total);
return 0;
}
double gettingInfo(double& processor, double& storage, double& ram, bool& touchscreen, char& touchscreenCheck)
{
cout<<"Enter processor speed: ";
cin>>processor;
errorChecking(processor);
cout<<"Enter storage amount: ";
cin>>storage;
errorChecking(storage);
cout<<"Enter RAM amount: ";
cin>>ram;
errorChecking(ram);
cout<<"Is your computer touchscreen(Y/N)? ";
cin>>touchscreenCheck;
if(touchscreenCheck=='Y'|| touchscreenCheck=='y')
touchscreen=true;
else
touchscreen=false;
}
double errorChecking(double& input)
{
while (input<=0){
cout<<"Please enter a number greater than zero: ";
cin>>input;
}
}
double calculatingPrice(double& processor, double& storage, double& ram, bool& touchscreen){
const double PC_BASE_COST=150;
const double PROCESSOR_SPEED_MAX=2;
const double XTRA_PROCESSOR_SPEED=50;
const double STORAGE_MAX=500;
const double XTRA_STORAGE=45;
const double RAM_MAX=4;
const double XTRA_RAM=5;
const double MARKUP=0.75;
const double TOUCHSCREEN_PRICE=60;
double extraProc;
double xtraRam;
double processorCost;
double storageCost;
double ramCost;
double cost;
double total;
double markupTotal;
double touchscreenCost;
if (processor>PROCESSOR_SPEED_MAX){
extraProc=processor-PROCESSOR_SPEED_MAX;
processorCost=extraProc*XTRA_PROCESSOR_SPEED;
}
else{
processorCost=0;
}
if (storage>=STORAGE_MAX){
storageCost=XTRA_STORAGE;
}
else{
storageCost=0;
}
if (ram>RAM_MAX){
xtraRam=ram-RAM_MAX;
ramCost=xtraRam*XTRA_RAM;
}
else{
ramCost=0;
}
if (touchscreen=1)
touchscreenCost=TOUCHSCREEN_PRICE;
else
touchscreenCost=0;
cout<<touchscreenCost;
cost=processorCost+storageCost+ramCost+touchscreenCost+PC_BASE_COST;
markupTotal=cost*MARKUP;
return total=cost+markupTotal;
}
double printingReciept(double& processor, double& storage, double& ram,double& total)
{
cout<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Processor Speed:\t"<<processor<<" GHz"<<endl;
cout<<"Storage Capacity:\t"<<storage<<" GB"<<endl;
cout<<"RAM Amount:\t\t"<<ram<<" GB"<<endl;
cout<<"Touchscreen:\t\t"<<endl;
cout<<"Total Cost:\t\t$"<<fixed<<setprecision(2)<<total<<endl;
}
cout<<"Touchscreen:\t\t"<<endl;
cout<<"Total Cost:\t\t$"<<fixed<<setprecision(2)<<total<<endl;
}
```

Last edited by a moderator: