❓ Help User-define header file error c++

Status
Not open for further replies.

IkaMusume

Forum Guru
Tanong ko lang po sana kasi kapag tinatype ko ang 1 sa choice dito sa output ko hindi niya tinatawag yung addition()
ps: hidepost ko na po muna, may nakikita kasi akong student dito na ka same school ko na leechers, for safety nadin po and para hindi mareport sa instructor ehe

1653555281252.webp

eto code ng menu ko

C++:
#include <iostream>
using namespace std;

int MENU()
{

cout << "====================== MAIN MENU ======================\n";
cout << "What function do you want to perform? \n";
cout << "1 - ADDITION\n";
cout << "2 - SUBTRACTION\n";
cout << "3 - MULTIPLICATION\n";
cout << "4 - DIVISION\n";
cout << "5 - GET AVERAGE\n";
cout << "6 - 100 MULTIPLES OF  A NUMBER\n";
cout << "7 - POWER OF A NUMBER\n";
cout << "8 - EXIT\n";
cout << "========================================================\n";
int choice=0;

while (choice <8)
    {
        cout << "Press 1 to 8 only: ";
        cin >> choice;
        if (choice >= 1 && choice < 8)
        {
            break;
        }
        else
        {
            cout << "Invalid Input. ";
        }
    }
    return 0;
}

yung pinapatawag ko naman na addition()
arithmetic.h
C++:
int addition()
{
    cout << "======================= ADDITION =======================\n";
    int n, num, sum=0;
    cout<<"How many numbers you want to input? ";
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cout << i+1 << ". ";
        cin>>num;
        sum = sum+num;
    }
    cout<<"\nSum of the "<<n<<" numbers you entered is "<<sum;
    cout<<endl;
    return 0;
}

sana po mapansin kung ano remediyong pwede kong gawin para matawag niya yung addition()
 
Code:
while (choice <8)
    {
        cout << "Press 1 to 8 only: ";
        cin >> choice;
        if (choice >= 1 && choice < 8)
        {
            break;
        }
        else
        {
            cout << "Invalid Input. ";
        }
    }
    return 0;
}

nandito yta issue mo. kasi yung choice is greater than 1. kya automatic mapunta sa if else break;.to test kung mapunta nga jan. try mo mag lagay ng print code before break or to test yung possible result na gusto mo.
{
cout << "Press 1 to 8 only: ";
cin >> choice;
if (choice >= 1 && choice < 8)
{
cout << "Invalid Input. ";
break;
}
else
{
cout << "Invalid Input. ";
}
}
 
Hindi mo po tinawag yung addition() na method nung inenter ni user ang 1, instead break po ang tinawag mo.
 
Code:
while (choice <8)
    {
        cout << "Press 1 to 8 only: ";
        cin >> choice;
        if (choice >= 1 && choice < 8)
        {
            break;
        }
        else
        {
            cout << "Invalid Input. ";
        }
    }
    return 0;
}

nandito yta issue mo. kasi yung choice is greater than 1. kya automatic mapunta sa if else break;.to test kung mapunta nga jan. try mo mag lagay ng print code before break or to test yung possible result na gusto mo.
{
cout << "Press 1 to 8 only: ";
cin >> choice;
if (choice >= 1 && choice < 8)
{
cout << "Invalid Input. ";
break;
}
else
{
cout << "Invalid Input. ";
}
}
ganito po sana yung expected kong output based sa output ng instructor ko
1653559053061.webp
.
tatawagin niya yung case 1 which is yung addition() na nasa arithmetic.h header file.
 
ganito po sana yung expected kong output based sa output ng instructor ko
View attachment 1955012.
tatawagin niya yung case 1 which is yung addition() na nasa arithmetic.h header file.
gawin mo nlng method yung choices. pra pwede mo tawagin ulit pag mali yung input.

if (choices == 0 || time < 0){
cout << "Invalid Input. ";
}else if (choices <= 1 || choices <= 8) {
cout << "Input Accepted. ";
} else {
cout << "Invalid Input. ";
}

ito try mo. tested na yan accepted input 1-8. invalid input 0 or negative & greater than 8.
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 665
    Views
  • 3
    Participants
Last reply from:
IkaMusume

Online now

Members online
1,006
Guests online
1,308
Total visitors
2,314

Forum statistics

Threads
2,277,039
Posts
28,973,868
Members
1,229,695
Latest member
Smile2742
Back
Top