[Solved] Novice C++ project using loops, if else and switch [closed]


This’ll work. Please cross-check output for different inputs for coz haven’t had the time to do so.

#include<iostream>
using namespace std;

int main (){
    int units;
    double priceA,priceB,priceC;
    char package, goAgain;

    do {
        cout << "Enter the Package chosen. Enter 'A' or 'a' for package A.\n";
        cout << "Enter 'b' or 'B' for package B.\n";
        cout << "Enter 'c' or 'C' for package C.\n";
        cin >> package;
        cout << "Enter the number of message units";
        cin >> units;

        priceA=15.95;
        priceB=25.95;
        priceC=45.95;

        if (units>20){
            priceB += (units-20)*.10;
            priceA += (units-10)*.20;
        }
        else if (units>10){
            priceA += (units-10)*.20;
        }

        switch(package)
        {
            case 'a':
            case 'A':   cout <<"\nThe cost of package A is" << " $" <<priceA << endl;
                        if(priceA>priceB)
                        {
                            cout << "\nBy switching to package B you would save" << " $" << priceA-priceB<<endl;
                        }
                        if(priceA>priceC)
                        {
                            cout << "\nBy switching to package C you would save" << " $" << priceA-priceC<<endl;
                        }
                        break;
            case 'b':  
            case 'B':   cout <<"\nThe cost of package B is" << " $" <<priceB << endl;
                        if(priceB>priceA)
                        {
                            cout << "\nBy switching to package A you would save" << " $" << priceB-priceA<<endl;
                        }
                        if(priceB>priceC)
                        {
                            cout << "\nBy switching to package C you would save" << " $" << priceB-priceC<<endl;
                        }
                        break;
            case 'c':
            case 'C':   cout <<"The cost of package C is" << " $" <<priceC << endl;
                        if(priceC>priceB)
                        {
                            cout << "\nBy switching to package B you would save" << " $" << priceC-priceB<<endl;
                        }
                        if(priceC>priceA)
                        {
                            cout << "\nBy switching to package A you would save" << " $" << priceC-priceA<<endl;
                        }
                        break;
            default: cout << "\nIncorrect Input!!";
        }

        cout<<"do you want to go again? y/n" << endl;
        cin >>goAgain;
    }
    while(goAgain=='y');
}

solved Novice C++ project using loops, if else and switch [closed]