Need help creating an equation in C++ to calculate total -
my updated code. when run code keeps outputting prices of packages instead of 1 ask for.
#include <iostream> using namespace std; int main() { // keep simple int choice_a = 995; int choice_b = 1995; int choice_c = 3995; char choice; int message_units, x=1; double price; bool selected = false; // loop shows options { cout << "which package choose (enter a, b or c)" << endl; // need check cin >> choice; // keeping simple if (choice == 'a') { price = choice_a; selected = true; } else if (choice == 'b') { price = choice_b; selected = true; } else if (choice == 'c') { price = choice_c; selected = true; } cout << endl; } // loops until selected while (selected == false); do{ cout << "how many message units (enter 1 - 672)" << endl; // again check cin >> message_units; x++; } while(x<2); if(message_units > 5){ choice_a += 100 * (message_units - 5); } cout << "your total cost " << choice_a /100 << "." <<choice_a%100 endl if(message_units > 15){ choice_b += 50 * (message_units - 15); } cout <<"yourtotalcostis"<<choice_b /100 << "." << choice_b%100<<endl;
(you missed "i" or two, english difficult non-native speaker.)
atotalcost = 9.95; if(messageunits>5) atotalcost += 1.0 * (messageunits-5);
edit:
there several ways deal amounts of money. 1 of them store amount number of cents, print out care. example, amount $2.34 stored int price = 234
, print out print price/100
(which 2), decimal point, price%100
(which 34, '%' modulo operator, can up). code this:
#include <iostream> using namespace std; int main() { int messageunits; cout << "how many message units(enter 1 - 672)" << endl; cin >> messageunits; int atotalcost = 995; // cost of package a, in cents if(messageunits > 5){ atotalcost += 100 * (messageunits - 5); } cout << "your total cost " << atotalcost/100 << "." << atotalcost%100 << endl; }
there still work do, start.
Comments
Post a Comment