开发者

conversion from `double' to non-scalar type requested and some other errors [closed]

开发者 https://www.devze.com 2023-04-12 17:01 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow sit开发者_如何学编程uation that is not
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow sit开发者_如何学编程uation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

Please read my code, and help me to debug it. because Dev-C++ finds a lot of errors....

#include<iostream.h>
#include<conio.h>
using namespace std;

struct iWorker{
       double salary;
}

double calSalary(iWorker worker){
    double money = worker.salary;
    return money;
}

int main(){
    iWorker worker;

    cout << "Enter salary: ";
    cin >> worker.salary;

    double salary = calSalary(worker, 0);
    cout << salary;

    getch();
    return 0;
}

and errors:

9: error: new types may not be defined in a return type
9: error: two or more data types in declaration of `calSalary'
 In function `iWorker calSalary(iWorker)':
11: error: conversion from `double' to non-scalar type `iWorker' requested

 In function `int main()':
9: error: too many arguments to function `iWorker calSalary(iWorker)'
20: error: at this point in file
20: error: cannot convert `iWorker' to `double' in initialization

Thank you ...


You're missing a ; after your struct declaration:

struct iWorker{
   ...
};  // <- this one here


struct iWorker{
       int id;
       char name[100];
       float hours;
       double salary;
} <--- missing semicolon here ...


Damn, I was too late. But you also have a possible buffer overrun in this line:

cin >> worker.name;

Why don't you use std::string?

0

精彩评论

暂无评论...
验证码 换一张
取 消