Help with Calculation

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 43
Reputation: hopeolicious is an unknown quantity at this point 
Solved Threads: 0
hopeolicious hopeolicious is offline Offline
Light Poster

Help with Calculation

 
0
  #1
Oct 14th, 2004
This is my program but i cant get it to calculate my cost
These are my calculations:
1) if the color of the car is blue and the cost of the car is less than 1200 add 10% of the cost of the car to the cost of the car

2) If the color of the car is black and the cost of the car is greater than 100 but less than 1500 add 20% of the cost of the car to the cost of the car

3) If the color of the car is white and cost is less than or equal to 2000 then subtract 500 from the cost of the car




// Description: Display person name, address, calculated and
// actual cost of car and color of car

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <iomanip.h>


int x;
char st_name[25];
char st_address[75];
char st_color[25];
float f_ccost;
float f_acost;


void getdata();
void processdata();
void putdata();


int main()
{
for(x=1;x<=3;x++)
{
getdata();
processdata();
putdata();
}
}
void getdata()
{
cout << "\n\nPlease enter your name: ";
cin.getline(st_name,25);

cout << "\n\nPlease enter your address: ";
cin.getline(st_address,75);

cout << "\n\nPlease enter the amount you paid for your car: ";
cin >> f_acost;

cin.get();

cout << "\n\nPlease enter your car color: ";
cin.getline(st_color,25);
}
void processdata()
{
cout << "\n\nCalculated amount of your car is: ";

if(f_acost < 1200)
{
if(strcmp(st_color,"blue")==0)
{
f_ccost = f_acost + 10.0/100;
cout << f_ccost;
}
else
{
cout << f_acost;
}
}
else if(f_acost > 1000.00 && f_acost < 1500.00)
{
if(strcmp(st_color,"black")==0)
{
f_ccost = f_acost + 2.0/100;
cout << f_ccost;
}
else
{
cout << f_acost;
}
}
else if(f_acost <= 2000.00)
{
if(strcmp(st_color,"white")==0)
{
f_ccost = f_acost - 500.00;
cout << f_ccost;
}
else
{
cout << f_acost;
}
}
else
{
cout << f_acost;
}

}
void putdata()
{
cout << "\n\nPerson Name: " << st_name;
cout << "\n\nAddress: " << st_address;

cout << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
cout << "\n\nActual Cost of Car: $ " << f_acost;
cout << "\n\nCalculated Cost of Car: $ " << f_ccost;
cout << "\n\nColor of Car: " << st_color;
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 29
Reputation: ZuK is an unknown quantity at this point 
Solved Threads: 0
ZuK ZuK is offline Offline
Light Poster

Re: Help with Calculation

 
0
  #2
Oct 14th, 2004
Hi
Your calculation of the percentage is wrong.
e.g you want to add 10% you write
  1. f_ccost = f_acost + 10.0/100;
but it should be
  1. f_ccost = f_acost + f_acost*10.0/100;
K.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC