mercredi 28 janvier 2015

issue with variable types

I am supposed to make a shipping program that asks the user some basic questions. Here are the instructions: An online shopper searches web to find an item and purchase is from the state with the lowest tax rate. Write a simple C++ program to do the following: Ask the user for the unit price of the item, the number of items the shopper wants to purchase, the name of the first state, the tax rate in the first state, the name of the second state and the tax rate in the second state. Then, calculate the total cost for each state and decide from which state the shopper should buy the item. Display the following to shopper: The unit item cost, the number of items purchased, the name and tax rate of the first state, the name and tax rate of the second state, and your recommendation on from which state the shopper should make the purchase.


List ALL literals and variables in your program.


Here is my code so far:



#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{
double itemPrice, numberItem, taxRate, totalCost;
double stateTax1, stateTax2;
int stateName1, stateName2;

// ask the item's price
cout << "What is the price of the item?\n";
cin >> itemPrice;

// ask the # items
cout << "How many items are you going to purchase?\n";
cin >> numberItem;

// ask the name of the first state
cout << "What state are you having it shipped to?\n";
cin >> stateName1;

// ask the tax rate of the first state
cout << "What is the tax rate in " << stateName1 << "?\n";
cin >> stateTax1;

// ask the name of the second state
cout << "What state are you having shipped from?\n";
cin >> stateName2;

// ask the tax rate of the second state
cout << "What is the tax rate in " << stateName2 << "?\n";
cin >> stateTax2;

// first if the first state has a lower tax rate
// else if second state has lower tax rate
if (stateTax1 < stateTax2)
{
totalCost = itemPrice * numberItem * stateTax1;

cout << "The item cost is " << itemPrice << ".\n";
cout << "The number of items is " << numberItem << ".\n";
cout << "The name of the first state is " << stateName1 << ".\n";
cout << "The tax rate of the first state is " << stateTax1 << ".\n";
cout << "The name of the second state is " << stateName2 << ".\n";
cout << "The tax rate of the second state is " << stateTax2 << ".\n";
cout << "You should consider purchasing the item from " << stateName1 << ".\n";
}
else
{
totalCost = itemPrice * numberItem * stateTax2;

cout << "The item cost is " << itemPrice << ".\n";
cout << "The number of items is " << numberItem << ".\n";
cout << "The name of the first state is " << stateName1 << ".\n";
cout << "The tax rate of the first state is " << stateTax1 << ".\n";
cout << "The name of the second state is " << stateName2 << ".\n";
cout << "The tax rate of the second state is " << stateTax2 << ".\n";
cout << "You should consider purchasing the item from " << stateName2 << ".\n";
}
return 0;
}


My question is how do I get the stateName variables to work properly. I am sure this is some basic string thing I should know but I do not. other than that I believe the rest of my code works properly. though any and all tips would be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire