Where am I going wrong with these calculations?

Hi, Im writing a program that has to calculate the cost of apples and oranges. Everything is fine except the part where I calculate the variables.

My teacher told me what to do between the *** near the bottom of my code. I dont understand what she wants me to do.

------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;

int main()
{
float numapples;
float numoranges;
float applecost=0;
float orangecost=0;
float numapple2;
float totalappcost;
float subtotal;
float total;



cout<<"Todays Special! Apples are 2 for 1. Buy one get one free! 1 apple for $1.00, 2 apples for $1.00, 3 apples equals $2.00, 4 apples equals $2.00, etc."<<endl;

cout<<endl;

cout<<"Another Special! How ever many oranges you buy will give you the same number of percentage off your total bill."<<endl;

cout<<endl;

cout<<"For example if you buy 10 oranges you get 10% off your total bill."<<endl;

cout<<endl;

cout<<"Please enter the amount of apples or oranges between 1 and 100."<<endl;

cout<<"How many apples do you want?"<<endl;
cin>>numapples;

cout<<"You want "<<numapples<<" apples.";

cout<<"How many oranges do you want?"<<endl;
cin>>numoranges;

cout<<"You want "<<numoranges<<" oranges.";

numapple2=numapples/2;
***Then cout the numapple2 to see that it calculated right. Do the same with the totalappcost and subtotal. You are doing this to see where the caculation is wrong.*****

totalappcost=numapple2*applecost;

subtotal=orangecost+totalappcost;

total=subtotal*.10;

cout<<"This is your total "<<total<<endl;

system("PAUSE");
return 0;
}
Last edited on
So, if every orange is $1, and I buy 200 oranges, does that mean I get paid $100? What a deal!

She just wants you to output the value of the variables.
How would I output the value of the variables?
Last edited on
Um... You don't know how? But you're already doing it:
cout<<"You want "<<numoranges<<" oranges.";
Last edited on
Lol, mistunderstanding :)
Alright but I still dont understand what I have to do next.
Well you have to look at the calculations:

1
2
3
totalappcost=numapple2*applecost;

subtotal=orangecost+totalappcost;


You have the calculations here, but they will always be 0, i.e. you have no cost value in your code.
Topic archived. No new replies allowed.