now i have create a code to calculate a formula but i have a problem with number 4,5,6,7 it can select but it not running. working principle of code is select a number in the box click enter and it will enter into that formula.i think my problem is a case function but i tried to fix and it can't.
....
#include<iostream>
#include<conio.h>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<windows.h>
#define PI 3.14159
using namespace std;
HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);
//set Color
void colorText(int i){
SetConsoleTextAttribute(h,i);
}
//Declaring Variable
float density(float mass, float volume){
return mass / (double)volume;
}
int exponent(int base,int index,int result){
return result = pow(base, index);
}
float hypotenuse(float A_side, float B_side,float c_side_result){
return c_side_result = sqrt((A_side*A_side)+(B_side*B_side));
}
float velocity(float velo, float initial, float acceleration, float time){
return velo = initial + (acceleration * time);
}
float mass_en(float mass_value, float speedlight_value, float energy){
return energy = mass_value * (speedlight_value * speedlight_value);
}
float percentage(float percent, float number, float base_per){
return percent = (number/base_per)*100;
}
// Main Menu
void main_Menu(){
colorText(11);
system("CLS");
cout << "----------------------\n";
cout << "* 6 Useful formula *\n";
cout << "----------------------\n";
cout << setw(3)<<"1.finding density \n";
cout << setw(3)<<"2.finding exponent\n";
cout << setw(3)<<"3.finding hypotenuse\n";
cout << setw(3)<<"4.finding velocity\n";
cout << setw(3)<<"5.finding mass\n";
cout << setw(3)<<"6.finding percentage\n";
cout << setw(3)<<"7.member\n";
cout << "----------------------\n";
}
//single Menu
void density_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding Density *\n";
cout << "---------------------\n";
}
void exponent_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding Exponent *\n";
cout << "---------------------\n";
}
void hypotenuse_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding Hypotenuse *\n";
cout << "---------------------\n";
}
void velocity_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding Velocity *\n";
cout << "---------------------\n";
}
void mass_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding Mass *\n";
cout << "---------------------\n";
}
void percentage_menu(){
system("CLS");
cout << "---------------------\n";
cout << "* finding percentage *\n";
cout << "---------------------\n";
}
int main(){
char choosechoice;
do{
main_Menu();
cout << "Press X or x to exit: ";
cin >> choosechoice;
switch(choosechoice){
case '1':
system("CLS");
float mass, volume;
cout << fixed;
cout << setprecision(2);
density_menu();
cout << "Enter Mass: ";
cin >> mass;
cout << "Enter Volume: ";
cin >> volume;
system("CLS");
density_menu();
cout << setw(10)<<"Mass: " << setw(6)<<mass << " kg"<< endl;
cout << setw(10)<<"Volume: " << setw(6)<<volume << " m^3"<< endl;
cout << setw(10)<<"Density: " << setw(6)<<density(mass,volume)<<" kg/m^3";
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '2':
system("CLS");
int base, index, result;
cout << fixed;
cout << setprecision(2);
exponent_menu();
cout << "Enter Base number: ";
cin >> base;
cout << "Enter Index number: ";
cin >> index;
system("CLS");
exponent_menu();
cout << setw(15)<<"Base number: " << setw(6)<<base << endl;
cout << setw(15)<<"Index number: " << setw(6)<<index << endl;
cout << setw(15)<<"Result: " << setw(6)<<exponent(base,index,result);
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '3':
system("CLS");
float A_side,B_side,c_side_result;
cout << fixed;
cout << setprecision(2);
hypotenuse_menu();
cout << "Enter A side: ";
cin >> A_side;
cout << "Enter B side: ";
cin >> B_side;
system("CLS");
hypotenuse_menu();
cout << setw(10)<<"Result: " << setw(6)<<hypotenuse(A_side,B_side,c_side_result);
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '4':
system("CLS");
float velo, initial, acceleration, time;
cout << fixed;
cout << setprecision(2);
velocity_menu();
cout << "Enter initial velocity: ";
cin >> initial;
cout << "Enter acceleration : ";
cin >> acceleration;
cout << "Enter time : ";
cin >> time;
system("CLS");
velocity_menu();
cout << setw(10)<<"Result: " << setw(6)<<velocity(velo,initial,acceleration,time);
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '5':
system("CLS");
float mass_value, speedlight_value, energy;
cout << fixed;
cout << setprecision(2);
mass_menu();
cout << "Enter Mass Value: ";
cin >> mass_value;
cout << "Enter Speed of light value : ";
cin >> speedlight_value;
system("CLS");
mass_menu();
cout << setw(10)<<"Result: " << setw(6)<<mass_en(mass_value, speedlight_value, energy);
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '6':
system("CLS");
float percent, number, base_per;
cout << fixed;
cout << setprecision(2);
mass_menu();
cout << "Type the number: ";
cin >> number;
cout << "Type the base: ";
cin >> base_per;
system("CLS");
percentage_menu();
cout << setw(10)<<"Result: " << setw(6)<<percentage(percent, number, base_per);
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
case '7':
system("CLS");
cout << fixed;
cout << setprecision(2);
cout << "---------------------------\n";
cout << " MEMBER \n";
cout << "Nattapon Sripradub M.4/1 No.14\n";
cout << "Natnicha Nuangsupthawee M.4/1 No.22\n";
cout << "Panicha Pornpattarapon M.4/1 No.24\n";
cout << "\n----------------------";
cout << "\nPress any key to return to main menu";
getch();
break;
}
}while(choosechoice!= 'X' && choosechoice != 'x');
return 0;
}
Related
I'm just starting in studying C++, and I am doing a simple challenge which is GWA Calculator, but I am having a problem finding out how to store the multiple strings input (which is the Subjects/Course) and displaying it after together with the Units and Grades. I am really sorry, but I tried finding out how and I couldn't find an answer. Hope you can help me out.
#include <stdlib.h>
using namespace std;
void calculateGWA();
int main()
{
system("cls");
int input;
cout << "\t\t -------------------------------------------------------------------------- " << endl;
cout << "\t\t| GWA Calculator |" << endl;
cout << "\t\t -------------------------------------------------------------------------- " << endl;
cout << "\t\t| MENU:\t\t\t\t\t\t\t " << "|" << endl;
cout << "\t\t| 1. Calculate GWA (General Weighted Average)\t\t " << "|" << endl;
cout << "\t\t| 2. Calculate CGWA (Cummulative Weighted Average) " << "|" << endl;
cout << "\t\t| 4. Exit Application\t\t\t\t\t " << "|" << endl;
cout << "\t\t| |" << endl;
cout << "\t\t -------------------------------------------------------------------------- " << endl;
sub:
cout << "\t\tEnter your choice: ";
cin >> input;
switch(input)
{
case 1:
calculateGWA();
break;
case 2:
//calculateCGPA();
break;
case 3:
main();
break;
case 4:
exit(EXIT_SUCCESS);
break;
default:
cout << "You have entered wrong input.Try again!\n" << endl;
goto sub;
break;
}
}
void calculateGWA()
{
int q;
system("cls");
cout << "-------------- GWA Calculator -----------------"<<endl;
cout << " How many course(s)?: ";
cin >> q;
char c_name[50];
float unit [q];
float grade [q];
cout << endl;
for(int i = 0; i < q; i++)
{
cout << "Enter the Course Name " << i+1 << ": ";
cin >> c_name;
cout << "Enter the Unit " << c_name << ": ";
cin >> unit[i];
cout << "Enter the Grade " << c_name << ": ";
cin >> grade[i];
cout << "-----------------------------------\n\n" << endl;
}
float sum = 0;
float tot;
for(int j = 0; j < q; j++)
{
tot = unit[j] * grade[j];
sum = sum + tot;
}
float totCr = 0;
for(int k = 0; k < q; k++)
{
totCr = totCr + unit[k];
}
system("cls");
// PRINTS OUT THE COURSES - UNITS - GRADES AND GWA //
cout << "\t\t =============================================================== " << endl;
cout << "\t\t| COURSE | UNIT | GRADE |" << endl;
cout << "\t\t =============================================================== " << endl;
cout << "Total Points: " << sum << " \n Total Credits: " << totCr << " \nTotal GPA: " << sum/totCr << " ." << endl;
cout << c_name << "\n" << endl;
cout << "===================================" << endl;
sub:
int inmenu;
cout << "\n\n\n1. Calculate Again" << endl;
cout << "2. Go Back to Main Menu" << endl;
cout << "3. Exit This App \n\n" << endl;
cout << "Your Input: " << endl;
cin >> inmenu;
switch(inmenu)
{
case 1:
calculateGPA();
break;
case 2:
main();
break;
case 3:
exit(EXIT_SUCCESS);
default:
cout << "\n\nYou have Entered Wrong Input!Please Choose Again!" << endl;
goto sub;
}
}
I am trying to build a menu on console on C++ with CodeBlock. Is for a course.
I would like to validate garbage enter by the user. For example, the user have to enter a number. If he enters a wrong number, no problem, the program work and continue. But if He enters a letter or some garbage, the program start on infinite loop.
I cannot use system(PAUSE) because I am programming on Linux.
I tried some code like cin.get() or do while with cin.get() but no result.
Here is my code :
#include <iostream>
using namespace std;
void showMenu()
{
cout << "---------------MENU --------------" << endl;
cout << "1- Check balance :" << endl;
cout << "2- Check deposit :" << endl;
cout << "3- Withdraw:" << endl;
cout << "4- Exit" << endl;
cout << "--------------------------------" << endl;
}
int main()
{
int option;
double balance = 500;
do
{
showMenu();
cout << "Option: ";
cin >> option;
cout << "\033[2J\033[1;1H";
switch(option)
{
case 1:
cout << "Balance is: " << balance << " $" << endl;
break;
case 2:
cout << "Deposit amount: " << endl;
double depositAmount;
cin >> depositAmount;
balance += depositAmount;
break;
case 3:
cout << "Withdraw amount: " << endl;
double withdrawAmount;
cin >> withdrawAmount;
if (withdrawAmount <= balance) {
balance -= withdrawAmount;
}
else {
cout << "Not enough money" << endl;
}
break;
default:
cout << "Your choice is invalid ";
do {
cout << '\n' << "Press the Enter key to continue.";
}while (cin.get() != '\n');
}
} while(option != 4);
return 0;
}
Do you have an idea how can I validate easily the garbage enter by the user ?
Thank you for your Help
It works with the code on default part : cin.clear and cin.ignore(). This last one is important. Thank you to user4581301
#include <iostream>
using namespace std;
void showMenu()
{
cout << "---------------MENU --------------" << endl;
cout << "1- Check balance :" << endl;
cout << "2- Check deposit :" << endl;
cout << "3- Withdraw:" << endl;
cout << "4- Exit" << endl;
cout << "--------------------------------" << endl;
}
int main()
{
int option;
double balance = 500;
do
{
showMenu();
cout << "Option: ";
cin >> option;
cout << "\033[2J\033[1;1H";
switch(option)
{
case 1:
cout << "Balance is: " << balance << " $" << endl;
break;
case 2:
cout << "Deposit amount: " << endl;
double depositAmount;
cin >> depositAmount;
balance += depositAmount;
break;
case 3:
cout << "Withdraw amount: " << endl;
double withdrawAmount;
cin >> withdrawAmount;
if (withdrawAmount <= balance) {
balance -= withdrawAmount;
}
else {
cout << "Not enough money" << endl;
}
break;
default:
cout << "\033[2J\033[1;1H"; //for clean screen with Linux
cout << "Your choice is invalid " << endl;
cin.clear();
cin.ignore();
}
} while(option != 4);
return 0;
}
when I'm executing this program, it works fine just for one option, but if I try to choose an other option when executing, it will throw an error in this line:
cout << "The available quantity is: " << *(it->second.find(disp)) << endl;
here's my program:
void avail_art(void)
{
char c,con;
int quantity,disp=MAX;
bool b = true;
map<string, unordered_set<int>>m{
{"Mouse",{120,disp}},
{"Keyboard",{75,disp}},
{"Monitor",{750,disp}},
{"GPU",{1200,disp}},
{"CPU",{1000,disp}}
};
auto it = m.find("CPU");
cout << "M - for mouse." << endl;
cout << "K - for keyboard." << endl;
cout << "R - for monitor." << endl;
cout << "G - for GPU." << endl;
cout << "C - for CPU." << endl;
cout << "Q - for quit." << endl;
cout << "======================" << endl;
while (b)
{
cout << "Enter your choice: ";
cin >> c;
switch (c)
{
case 'M':
it = m.find("Mouse");
cout << "You've choosen the Mouse!" << endl;
cout << "The available quantity is: " << *(it->second.find(disp)) << endl;
l:
cout << "Enter the quantity: ";
cin >> quantity;
if (quantity > * (it->second.find(disp)))
{
cout << "Out of Stock! the Stock has only :" << *(it->second.find(disp)) <<" Piece."<< endl;
goto l;
}
cout << "Confirm? y/n: ";
cin >> con;
if (con == 'y')
{
auto its=it->second.find(disp);
it->second.insert(disp=(*its - quantity));
it->second.erase(its);
}
break;
case 'K':
it = m.find("Keyboard");
cout << "You've choosen the Keyboard!" << endl;
cout << "The available quantity is: " << *(it->second.find(disp)) << endl;
cout << "Enter the quantity: ";
cin >> quantity;
cout << "Confirm? y/n :";
cin >> con;
if (con == 'y')
{
auto its = it->second.find(disp);
it->second.insert(disp = (*its - quantity));
it->second.erase(its);
}
break;
}
}
}
can someone help me please
so I have a school project where I'm trying to create a bank account. So I have an array of class customer containing the customer name etc, this customer can have multiple accounts, so I have created an array of class accounts inside of customer. My problem is, I can't call a getter function inside of the account array, I have tried using customerArray[curr_id]->accountArray[curr_acc_num]->get_balance() however I am getting an error telling my that it is unaccessable.
Here is the code, any input would be apprechiated as it is still a work in progress.
#include <iostream>.
#include <windows.h>
#include "account.h"
#include "customer.h"
using namespace std;
bool quit;
int amount;
double bal;
bool valid_pin;
customer* customerArray[200];
account* accountArray[5];
int curr_id;
int curr_acc_num;
//1st name, 2nd name, ID
customer cust1("Paul", "Smith", 2233);
//ID, Deposit, Pin
account Paul(112, 222, 6716);
//Welcome screen function
void welcome_screen() {
cout << endl << endl << endl;
cout << "\tAbertay Banking" << endl;
cout << "\t System " << endl << endl << endl;
Sleep(1800);
}
//Display account balance function
void account_balance() {
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << " " << customerArray[curr_id]->get_name() << endl;
cout << " ID: " << customerArray[curr_id]->get_custid() << endl << endl;
cout << " Balance: " << char(156) << customerArray[curr_id]->accountArray[curr_acc_num]->get_balance() << endl;
//Display any outstanding loans
if (Paul.get_loan() > 0) {
cout << endl << endl;
cout << " Outstanding loan: -" << char(156) << Paul.get_loan();
Sleep(3000);
}
//User has no loan on this account
else {
Sleep(3000);
}
}
//Withdrawl function
void withdrawl() {
bal = Paul.get_balance();
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Enter the amount you wish to withdraw: ";
cin >> amount;
//customer has sufficent funds, withdrawl accepted
if (amount <= bal + Paul.get_overdraft()) {
bal -= amount;
Paul.set_balance(bal);
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl; cout << "You have withdrawn: " << char(156) << amount << endl;
cout << "You now have a balance off: " << char(156) << bal << endl;
cout << "Do you wish to carry out another transaction?"; //do you wish to carry out another transaction.
Sleep(2000);
}
//customer doesn't have enough funds to carry out withdrawl
else {
char choice;
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "You have insufficient funds in your account" << endl;
}
}
//Deposit function
void deposit() {
//balance from user account
bal = Paul.get_balance();
char check;
double ln;
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Enter the amount you wish to deposit: ";
cin >> amount;
//Option to pay off loan, if applicable
if (Paul.get_loan() > 0) {
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Do you want to pay off your loan? (Y/N)" << endl;
cin >> check;
system("cls");
cout << "\tBank of Abertay" << endl << endl;
//User selected to pay off loan
if (check == 'y') {
//deposit paid into loan
if (amount < Paul.get_loan()) {
ln = Paul.get_loan() - amount;
Paul.set_loan(ln);
cout << "Your loan is now at: -" << char(156) << Paul.get_loan() << endl;
}
//loan is payed of, any extra money is deposited into balance
else {
ln = amount - Paul.get_loan() + Paul.get_balance();
Paul.set_loan(0);
Paul.set_balance(ln);
cout << "You have payed your loan off!" << endl;
}
}
}
//user has no loan or doesn't wish to pay off loan
else {
bal += amount;
Paul.set_balance(bal);
}
cout << "You have deposited: " << char(156) << amount << endl;
cout << "You now have a balance off: " << char(156) << bal << endl;
cout << "Would you like to select another option with this account?"; //do you wish to carry out another transaction.
Sleep(1500);
}
//Apply for overdraft
void overdraft() {
system("cls");
char choice;
cout << endl << endl;
cout << "\tTake out an overdraft of " << char(156) << "300? " << endl;
cout << "\t (Y/N)" << endl;
cin >> choice;
if (choice == 'y') {
Paul.set_overdraft(300);
}
}
//Calculating interest rates
double interest_rate(int loan) {
//Up to £3,000 rate of 11%
if (loan < 3000) {
return 1.11;
}
//From £3,000 to £7,000 rate of 9%
else if (loan > 3000 && loan < 7000) {
return 1.09;
}
//From £7,000 to £21,000 rate of 7%
else if (loan > 7000 && loan < 21000) {
return 1.07;
}
//From £21,000 over rate of 5%
else if (loan < 21) {
return 1.05;
}
}
//Loan eligibility funcition
void loan_elgibility() {
double max_loan;
double loan;
//Calculating loan eligibility
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Caculating loan eligibility";
max_loan = (2 * Paul.get_balance());
Sleep(800);
//Loan and rates
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << " You are eligible to borrow up to: " << char(156) << max_loan << endl << endl;
cout << " Interest rates are as follows" << endl << endl;
cout << " - " << char(156) << "3,000 at 11%" << endl;
cout << " " << char(156) << "3,000 - " << char(156) << "7,000 at 9%" << endl;
cout << " " << char(156) << "7,000 - " << char(156) << "21,000 at 7%" << endl;
cout << " " << char(156) << "21,000 - at 5%" << endl;
Sleep(6200);
//User input loan request
system("cls");
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << " Enter loan request: " << char(156);
cin >> loan;
//Processing loan request
system("cls");
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << " We are processing your request..." << endl;
Sleep(800);
system("cls");
//Loan has been approved, loan deposited into account
if (loan <= Paul.get_balance()) {
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << "Your loan has been approved" << endl;
bal = Paul.get_balance() + loan;
loan = interest_rate(loan) * loan;
Paul.set_balance(bal);
Paul.set_loan(loan);
Sleep(800);
}
//Loan has not been approved
else {
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << "You do not qualify for a loan of this amount";
Sleep(800);
}
}
//Quit function
void quit_screen() {
system("cls");
char choice;
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << " Do you want to quit? (Y/N) " << endl;
cout << " ";
cin >> choice;
// customer wants to quit, end while loop and program
if (choice == 'y') {
system("cls"); //clear screen
cout << endl << endl << endl;
cout << " Thanks for using," << endl;
cout << " Bank of Abertay!"<< endl;
Sleep(2000);
quit = true;
}
else {
quit = false;
}
}
//Request user pin number
bool pin_request() {
double pin;
int counter = 0;
do {
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "\tEnter pin: ";
cin >> pin;
if (pin == Paul.get_pin()) {
return true;
}
else if (counter == 3) {
cout << "You have entered an invalid pin too many times!";
Sleep(800);
return false;
}
else {
system("cls");
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << "You have entered an invalid pin" << endl;
Sleep(800);
valid_pin = false;
counter++;
}
} while (valid_pin == false && counter < 3);
}
//Adding a new customer
int counter = 0;
void add_customer(string first_nom, string second_nom, int cust_ID) {
customer* new_customer = new customer(first_nom, second_nom, cust_ID);
customerArray[counter] = new_customer;
counter++;
}
//creating new bank account
void create_account()
{
int input_custid;
double input_balance;
int input_pin;
string first_nom;
string second_nom;
int cust_ID;
char choice;
//Request new customer information
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Enter first name: ";
cin >> first_nom;
cout << endl;
cout << "Enter surname: ";
cin >> second_nom;
cout << endl;
cout << "Customer ID: ";
cin >> cust_ID;
//create new customer class array
add_customer(first_nom, second_nom, cust_ID);
//creating new account array
system("cls");
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "Enter The account No. :";
cin >> input_custid;
cout << "Initial deposit in new account: ";
cin >> input_balance;
cout << "Create pin: ";
cin >> input_pin;
system("cls");
cout << " We are processing your request..." << endl;
Sleep(800);
cust1.add_account(input_custid, input_balance, input_pin);
system("cls");
cout << "Account Created.." << endl;
cout << "Thank you for joining the Bank of Abertay";
Sleep(800);
}
//find user account
bool find_account() {
int custID;
int counter;
bool found_account;
system("cls");
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << " Enter your customer ID: ";
cin >> custID;
cout << " - ";
cin >> curr_acc_num;
//not happy about this!!
for (int i = 0; i < 200; i++) {
if (customerArray[i]->get_custid() == custID) {
curr_id = i;
return true;
}
else if (i == 199) {
return false;
}
}
}
//an option to send money to another account?
// need a function that takes user back to option menu if wrong pin enter!
int main() {
//welcome screen
welcome_screen();
//while loop until player decides to quit
do {
int option_choice;
system("cls"); //clear screen, updating board every time function called
cout << endl << endl;
cout << "\tBank of Abertay" << endl << endl;
cout << "\t Menu" << endl << endl;
cout << "\t1. View Balance" << endl;
cout << "\t2. Withdraw" << endl;
cout << "\t3. Deposit" << endl;
cout << "\t4. Loan eligibility" << endl;
cout << "\t5. New account" << endl;
cout << "\t6. Overdraft" << endl;
cout << "\t7. Quit" << endl << endl;
cout << "\t\tSelect: ";
cin >> option_choice;
//ensure option screen only runs through once unless an invalid option is chosen
int valid_number_check = 0;
// do {
switch (option_choice) {
//Display account balance
case 1:
if (find_account() == true && pin_request() == true) {
account_balance();
break;
}
else {
cout << "Your request has been denied";
break;
}
//Account withdrawl
case 2:
if ( find_account() == true && pin_request() == true) {
withdrawl();
break;
}
else {
cout << "Your request has been denied";
break;
}
//Account deposit
case 3:
if (find_account() == true && pin_request() == true) {
deposit();
break;
}
else {
cout << "Your request has been denied";
break;
}
//Loan eligibility
case 4:
if (find_account() == true && pin_request() == true) {
loan_elgibility();
break;
}
else {
cout << "Your request has been denied";
break;
}
//Create new account
case 5:
create_account();
break;
//Overdraft
case 6:
if (find_account() == true && pin_request() == true) {
overdraft();
break;
}
else {
cout << "Your request has been denied";
break;
}
//Quit
case 7:
quit_screen();
break;
//Invalid number entered
default:
cout << endl << endl;
cout << " Bank of Abertay" << endl << endl;
cout << "Please enter a valid number";
Sleep(800);
break;
}
} while (quit == false);
}
// main
Account .h
#pragma once
#include <string>
#include "account.h"
using namespace std;
class customer
{
private:
int custid;
string name;
account* accountArray[5];
int counter = 0;
public:
int get_custid();
customer(string, string, int);
string get_name();
void add_account(int, double, int);
~customer();
};
Account.cpp
#include "customer.h"
#include "account.h"
#include <string>
using namespace std;
customer::customer(string first_nom, string second_nom, int cust_ID) {
counter++;
string first_name = first_nom;
string sur_name = second_nom;
//counting the number of accounts
counter++;
//identification of customer array
//custid = counter + 1000;
custid = cust_ID;
}
customer::~customer()
{
}
int customer::get_custid() {
return custid;
}
void customer::add_account(int id, double dep, int pin) {
account* new_account = new account(id, dep, pin);
accountArray[counter] = new_account;
counter++;
}
string customer::get_name() {
return name;
}
customer.h
#pragma once
class account
{
private:
double balance;
int custid;
double loan_amount;
double overdraft;
int pin;
int account_number;
public:
account(int, double, int);
~account();
//getters
double get_balance();
double get_loan();
double get_pin();
double get_overdraft();
//setters
void set_overdraft(double over);
void set_balance(double bal);
void set_loan(double loan);
};
customer.cpp
#include "account.h"
#include <iostream>
#include <windows.h>
using namespace std;
account::account(int input_custid, double input_balance, int input_pin)
{
custid = input_custid;
balance = input_balance;
pin = input_pin;
loan_amount = 0;
overdraft = 0;
}
account::~account()
{
}
double account::get_balance()
{
return balance;
}
double account::get_loan()
{
return loan_amount;
}
double account::get_pin()
{
return pin;
}
double account::get_overdraft()
{
return overdraft;
}
void account::set_balance(double bal)
{
balance = bal;
}
void account::set_loan(double loan)
{
loan_amount = loan;
}
void account::set_overdraft(double over)
{
overdraft = over;
}
I am working on an assignment. The problem I am having is every time I try to run my program to see what it displays, nothing shows up on the command prompt. However, if I press any key and then enter, the program starts looping uncontrollably. The program doesn't even display the initial cout message, just a blinking "_". Thanks
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
void PizzaMenu();
void SizePrices();
int main()
{
double personal = 10.00;
double medium = 14.50;
double large = 19.00;
double xlarge = 23.50;
double FlavorChoice=0;
int SizeChoice;
int PizzaCountP=(cin >> PizzaCountP, PizzaCountP);
int PizzaCountM = (cin >> PizzaCountM, PizzaCountM);
int PizzaCountL = (cin >> PizzaCountL, PizzaCountL);
int PizzaCountXL = (cin >> PizzaCountXL, PizzaCountXL);
double orderTotal = (personal * PizzaCountP) + (medium * PizzaCountM) + (large * PizzaCountL) + (xlarge * PizzaCountXL);
cout << "Welcome to Joes pizza place!" << endl;
do{
PizzaMenu();
cout << "\nPlease chose a pizza from the menu(1-6): ";
cin >> FlavorChoice;
SizePrices();
cin >> SizeChoice;
if (SizeChoice > 0 && SizeChoice < 5)
{
switch (SizeChoice)
{
case 1:
cout << "How many personal pizzas? "; cin >> PizzaCountP;
break;
case 2:
cout << "How many medium pizzas?"; cin >> PizzaCountM;
break;
case 3:
cout << "How many large pizzas?"; cin >> PizzaCountL;
break;
case 4: cout << "How many extra large pizzas?"; cin >> PizzaCountXL;
break;
default: cout << "please enter a choice (1-4)"; cin >> SizeChoice;
break;
}
}
if (PizzaCountP > 0 || PizzaCountM > 0 || PizzaCountXL > 0 || PizzaCountL > 0)
{
printf("Your total is: %a", orderTotal);
}
} while (FlavorChoice != 6);
cout << "Thank you for visiting Joes place pizza! "<<endl;
}
void PizzaMenu()
{
cout << "\nSpecialty Pizza Menu" << endl;
cout << "\n1)Pizza 1" << endl << "\n2)Pizza 2" << endl << "\n3)Pizza 3" <<endl << "\n4)Pizza 4" << endl << "\n5)Pizza 5" << endl << "\n6)Pizza 6" << endl;
}
void SizePrices()
{
cout << "1) 10'' Personal" << "\t" << "- $10.00" << endl;
cout << "2) 14'' Medium" << "\t" << "- $14.50" << endl;
cout << "3) 16'' Large" << "\t" << "- $19.00" << endl;
cout << "4) 18'' Extra Large" << "\t" << "- $23.50" << endl;
cout << "Your choice (1-4)? ";
}
There were a few logical errors in the program. Right now, it should work fine...
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
void PizzaMenu()
{
cout << "Specialty Pizza Menu:" << endl;
cout << "1) Pizza 1" << endl << "2) Pizza 2" << endl << "3) Pizza 3" << endl << "4) Pizza 4" << endl << "5) Pizza 5" << endl << "6) Exit" << endl;
}
void SizePrices()
{
cout << "Size Prices:" << endl;
cout << "1) 10'' Personal" << "\t" << "- $10.00" << endl;
cout << "2) 14'' Medium" << "\t" << "- $14.50" << endl;
cout << "3) 16'' Large" << "\t" << "- $19.00" << endl;
cout << "4) 18'' Extra Large" << "\t" << "- $23.50" << endl;
cout << "Your choice (1-4)? ";
}
int main()
{
double personal = 10.00;
double medium = 14.50;
double large = 19.00;
double xlarge = 23.50;
int FlavorChoice = 0;
int SizeChoice = 0;
int PizzaCountP = 0;
int PizzaCountM = 0;
int PizzaCountL = 0;
int PizzaCountXL = 0;
double orderTotal = 0.0;
cout << "Welcome to Joes pizza place!" << endl;
cout << "Please choose from the main menu(1-6): " << endl;
PizzaMenu();
cin >> FlavorChoice;
while(FlavorChoice != 6) {
SizePrices();
cin >> SizeChoice;
if (SizeChoice > 0 && SizeChoice < 5)
{
switch (SizeChoice)
{
case 1:
cout << "How many personal pizzas? ";
cin >> PizzaCountP;
orderTotal += personal * PizzaCountP;
break;
case 2:
cout << "How many medium pizzas?";
cin >> PizzaCountM;
orderTotal += medium * PizzaCountM;
break;
case 3:
cout << "How many large pizzas?";
cin >> PizzaCountL;
orderTotal += large * PizzaCountL;
break;
case 4: cout << "How many extra large pizzas?";
cin >> PizzaCountXL;
orderTotal += xlarge * PizzaCountXL;
break;
default: cout << "please enter a choice (1-4)";
cin >> SizeChoice;
break;
}
}
// orderTotal = (personal * PizzaCountP) + (medium * PizzaCountM) + (large * PizzaCountL) + (xlarge * PizzaCountXL);
if (PizzaCountP > 0 || PizzaCountM > 0 || PizzaCountXL > 0 || PizzaCountL > 0)
{
// printf("Your total is: %a", orderTotal);
cout << "Your total is: $" << orderTotal << endl;
}
cout << "Please choose from the main menu(1-6): " << endl;
PizzaMenu();
cin >> FlavorChoice;
}
cout << "Thank you for visiting Joes place pizza! " << endl;
// system("pause");
return 0;
}