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
?
精彩评论