我想同时使用两个重复的函数,我有一个问题:
我有两个功能。每个都使用同一头文件中的其他函数。但是当我想在上面的函数中使用下面的函数时,我有一个错误。我知道,发生了什么,但我不知道如何解决它。我的代码:
主要.cpp:
include <iostream>
#include <cstdlib>
#include <C:\Users\Natch\Documents\CPP\Calc\incls.h>
using namespace std;
//Global vars
//Global functions
//Main program
int main() {
menu(1);
system("pause");
}
包括.h:
#ifndef INCLS_H_INCLUDED
#define INCLS_H_INCLUDED
#endif // INCLS_H_INCLUDED
#include <iostream>
#include <cstdlib>
using namespace std;
//Vars
int a, b, func, sa, ctrl;
long double sum, sqrt;
//Voids
void down(int func) {
if (func < 6) {
cout << "Wprowadz pierwszy skladnik dzialania:" << endl;
cin >> a;
cout << "Wprowadz drugi skladnik dzialania:" << endl;
cin >> b;
switch(func){
case 1:
sum = a+b;
cout << "Wynik wynosi: " << sum << endl;
menu(2);
break;
case 2:
sum = a-b;
cout << "Wynik wynosi: " << sum << endl;
break;
case 3:
sum = a*b;
cout << "Wynik wynosi: " << sum << endl;
break;
case 4:
sum = a/b;
cout << "Wynik wynosi: " << sum << endl;
break;
case 5:
sum = a%b;
cout << "Wynik wynosi: " << sum << endl;
break;
}
}else if (func == 6)
{
cout << "Podaj ilosc liczb do obliczenia sredniej:" << endl;
cin >> sa;
}else if (func == 7)
{
cout << "Podaj liczbe do wyciagniecia pierwiastka:" << endl;
cin >> a;
}else if (func == 8)
{
cout << "Podaj liczbe do wyciagniecia potegi:" << endl;
cin >> a;
}else if (func== 9)
{
system("exit");
}
}
void menu(int ctrl) {
if (ctrl==1){
system("cls");
system("color 06");
cout << "Kalkulator" << endl;
cout << "Wybierz funkcje: " << endl;
cout << "1.Dodawanie" << endl;
cout << "2.Odejmowanie" << endl;
cout << "3.Mnozenie" << endl;
cout << "4.Dzielenie" << endl;
cout << "5.Reszta z dzielenia" << endl;
cout << "6.Srednia arytmetyczna" << endl;
cout << "7.Pierwiastek kwadratowy" << endl;
cout << "8.Potega n^2" << endl;
cout << "9.Wyjscie" << endl;
cout << "Twoj wybor:" << endl;
cin >> func;
down(func);
}else if (ctrl==2){
cout << endl;
cout << endl;
cout << endl;
cout << endl;
menu(1);
}
}