im writing this program that calculates the price of fruits but for some reason it is not calcualting right. any suggetstions?
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main ()
{
double total;
int quantity;
string mystrng;
char answ;
double price;
double Apples = .99;
double Bananas = 1.00;
double Oranges = .50;
double Pears = 2.49;
double Grapes = 1.29;
cout << "Produce List:"<< endl ;
cout << "Apples- .99" << endl;
cout << "Bananas- 1.00" << endl;
cout << "Oranges- .50" << endl;
cout << "Pears- 2.49" << endl;
cout << "Grapes- 1.29" << endl;
cout << "What fruit do you want? ";
cin >> mystrng;
cout << "You have chosen " << mystrng << endl;
cout << "Do you want to purchase anymore fruit? ";
cin >> answ;
total = price * quantity;
if (answ = 'y' || 'Y')
{
cout << "Produce List:"<< endl ;
cout << "Apples- .99" << endl;
cout << "Bananas- 1.00" << endl;
cout << "Oranges- .50" << endl;
cout << "Pears- 2.49" << endl;
cout << "Grapes- 1.29"<< endl ;
cout << "You have chosen " << mystrng << endl;
cout << "Do you want to purchase anymore fruit? ";
}
else
{
cout << "Thank You " << "Your total is " << total << endl;
}
system("PAUSE");
return 0;
}
You are not assigning a value to price
or quantity
so total
will never be valid.