What's new

C++ code help

potatoXfries

Eternal Poster
Joined
Feb 9, 2018
Posts
689
Reaction
604
Points
491
pa help po sa paggawa ng code di po gumagana yung code na nagawa ko po e wrong computation

Screenshot_2021-11-27-18-51-25-41.jpg

ito po yung ginawa ko may mali sa computation di ko pa po ginawa yung married na part kasi mali na yung single e
Screenshot_2021-11-29-16-32-00-22_a927ed2714ba3b9021f681846134c26f.jpg

Screenshot_2021-11-29-16-33-10-09_a927ed2714ba3b9021f681846134c26f.jpg

it should be 3,350
 

Attachments

Dapat && ang gamitin mo sa pacheck ng income, hindi ||. At isama mo na rin ang equal sign.

C++:
if (income > 0 && income <= 8000)
 
Code:
#include <iostream>
using namespace std;

int main(){
    double income=0.0;
    double taxP1 = 0.10, taxAdd1 = 0.0, taxOver1=0.0;
    double taxP2 = 0.15, taxAdd2 = 800.0, taxOver2=8000.0;
    double taxP3 = 0.25, taxAdd3 = 4400.0, taxOver3=32000.0;

    double taxAdd1M = 0.0, taxOver1M=0.0;
    double taxAdd2M = 6000.0, taxOver2M=16000.0;
    double taxAdd3M = 8800.0, taxOver3M=64000.0;

    double TotalTax = 0.0;
    char status = ' ';

    cout<<"Welcome to TAX Computation Program"<<endl;
    cout<<"Please choose: [S] - Single [M] - Married"<<endl;
    cout<<"Please enter your status: ";
    cin>>status;
    cout<<endl;
    switch(status) {
        case 'S': case 's':
            cout<<"Enter amount (Income): ";
            cin>>income;
            if(income>=0 && income<8000){
                TotalTax = (income - taxOver1) * taxP1 + taxAdd1;
            }
            else if(income>=8000 && income<32000){
                TotalTax = (income - taxOver2) * taxP2 + taxAdd2;
            }
            else if(income>=32000){
                TotalTax = (income - taxOver3) * taxP3 + taxAdd3;
            }
            else{
                cout<<"No negative income";
            }

            cout<<"Total Tax Amount Due: "<<TotalTax<<endl;
            break;

        case 'M': case 'm':
            cout<<"Enter amount (Income): ";
            cin>>income;
            if(income>=0 && income<16000){
                TotalTax = (income - taxOver1M) * taxP1 + taxAdd1M;
            }
            else if(income>=16000 && income<64000){
                TotalTax = (income - taxOver2M) * taxP2 + taxAdd2M;
            }
            else if(income>=64000){
                TotalTax = (income - taxOver3M) * taxP3 + taxAdd3M;
            }
            else{
                cout<<"No negative income";
            }

            cout<<"Total Tax Amount Due: "<<TotalTax;
            break;

        default:
            cout<<"[S] or [M] only"<<endl;
    }
    cout<<endl;
    return 0;
}
 

Similar threads

Back
Top