| | |
Help with Calculation
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 43
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
Hi
Your calculation of the percentage is wrong.
e.g you want to add 10% you write
but it should be
K.
Your calculation of the percentage is wrong.
e.g you want to add 10% you write
C++ Syntax (Toggle Plain Text)
f_ccost = f_acost + 10.0/100;
C++ Syntax (Toggle Plain Text)
f_ccost = f_acost + f_acost*10.0/100;
![]() |
Similar Threads
- Help with calculation (VB.NET)
- 2d address calculation (C++)
- leap year calculation (ASP)
- Auto Calculation (Visual Basic 4 / 5 / 6)
- Need help with calculation (VB.NET)
- Mortgage Calculation (Java)
Other Threads in the C++ Forum
- Previous Thread: Urgent!
- Next Thread: While and Do While Help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





