Hello, I just recently started learning C ++, so the problem may seem stupid, but I hope that you will help.
The problem is this, I decided for practice to write a simple program that asks for the number of dishes ordered, their names and price, and then displays it with the total amount.
For prices and names of dishes made two vectors, and the output and the calculation of the amount allocated in a separate function, but the compiler swears to call this function and gives the error "no matching function for call to" total ". I tried to do the same with the usual array and it all worked, but I still want to know what was wrong with the vectors.
#include <string> #include <iostream> #include <vector> using namespace std; void line(){ for (int i=0; i<46; i++) { cout<<"*"; } cout<<endl; } int total(int kol_vo, string dish[], int cost[]){ int sum=0; line(); for (int i=0; i<kol_vo; i++) { sum+=cost[i]; cout<<dish[i]<<" : "<<cost[i]<<endl; } line(); return sum; } int main(){ cout<<"Введите количество позиций: "; int kol; cin>>kol; vector<string>dishes(kol); vector<string>cost(kol); for (int i=0; i<kol; i++) { cout<<"Введите название блюда "<<i+1<<": "; cin>>dishes[i]; cout<<"Введите цену блюда "<<i+1<<": "; cin>>cost[i]; } cout<<"Общий счёт: "<<total(kol,dishes, cost);//Вот тут показывает ошибку return 0; }