943,940 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1950
  • C++ RSS
Oct 14th, 2004
0

Help with Calculation

Expand Post »
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;
}
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
hopeolicious is offline Offline
43 posts
since Oct 2004
Oct 14th, 2004
0

Re: Help with Calculation

Hi
Your calculation of the percentage is wrong.
e.g you want to add 10% you write
C++ Syntax (Toggle Plain Text)
  1. f_ccost = f_acost + 10.0/100;
but it should be
C++ Syntax (Toggle Plain Text)
  1. f_ccost = f_acost + f_acost*10.0/100;
K.
ZuK
Reputation Points: 11
Solved Threads: 0
Light Poster
ZuK is offline Offline
29 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Urgent!
Next Thread in C++ Forum Timeline: While and Do While Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC