解决先生问题PLZ ??? [英] solve mr problem plz???

查看:78
本文介绍了解决先生问题PLZ ???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有消息

there are the messages

Compiling NONAME00.CPP:
Error NONAME00.CPP 25: Undefined symbol 'income' in function main()
Error NONAME00.CPP 42: Expression syntax in function main()
Error NONAME00.CPP 57: If statement missing ) in function main()




这是我的程序




this is my program

#include<stdio.h>
struct income_information{
  float Basic_salary;
  float overtime;
};

struct record{
  int id,number;
  char *starting_time;
  char *name;

  struct income_information income;

}worker[5];

main()
{

  income.Basic_salary;
  income.overtime;

  for(int i=0;i<5;i++)
  {
    printf("Worker[i]\n name: ");
    scanf(" %s",&income.name[i]);
    printf("ID number:");
    scanf("%d",&income.id[i]);
    printf("contact number:");
    scanf("%d",&income.number[i]);
    printf("starting date:");
    scanf(" %c",&income.starting_time[i]);
    printf("Basic Salary:");
    scanf("%f",&income.Basic_salary[i]);
    printf("over itme:");
    scanf("%f",&income.overtime[i]);
    if(20=>income.overtime[i]=<39)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*2.50);
    }
    else
    if(40>=>income.overtime[i]=<49)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*4.2);
    }
    else
    if(50=>income.overtime[i]=<60)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*5);
    }

    printf("Deduction: \tKWSP = %f \t\tsocso =    %f",income.Basic_salary[i]/11,income.Bas…
}

return i;





当我想在c ++ turbo上对其进行编译时,它向我显示3个错误. .i无法修复该错误

告诉我怎么做?





when i want to compiler it at c++ turbo it shows to me 3 errors. .i couldn''t fix that errors

tell me how??

推荐答案

您应该仔细阅读错误消息,它们通常非常有用.如果在阅读它们后您仍然卡住,请在此处发布它们.
:)
You should carefully read the error messages, they are usually pretty informative. If after reading them you''re still stuck, please post them here.
:)


我可以立即发现的一件事是代码的主要功能内的最后一行.该行是不完整的,并以看起来像椭圆的奇怪字符结尾.如果在您的代码中看起来像这样,我不会感到惊讶,那里有错误.

我也同意voloda2的观点,您至少可以做的就是提供编译器抛出的错误的全部详细信息.

问候,

曼弗雷德(Manfred)
One thing I can spot straight away is the last line inside the main function of your code. The line is incomplete and ends with a strange character that looks like an ellipse. If it looks that way in your code I wouldn''t be surprised there are errors.

I too agree with voloda2 that the least you could do is to provide as with the full details of the errors the compiler threw at you.

Regards,

Manfred


您的代码有各种各样的问题,这表明对编码缺乏基本的了解.如果要上课,则需要将此代码显示给老师或请教.如果您不上课,那就上课吧!

您显然不了解面向对象的编程.在这种编程风格中,您正在处理对象,例如房屋.现在,那所房子可以有房间了.它可以有任意数量的房间.这些房间可以摆放家具...所有不同类型的家具.而且家具可以具有不同的属性,例如织物,颜色,大小等...

这就是您在这里所做的.首先,您要创建两种新类型的对象,income_informationrecord. struct关键字告诉编译器您正在创建新的对象类型.但是,立即定义income_information(使用struct关键字),然后定义记录,然后在record中定义一个新对象,也称为income_information.

尝试将对象添加到另一个对象时,请勿使用struct关键字.

就您而言,记录应为:

you have all kinds of issues with your code and it shows a lack of basic understanding of coding. If you are taking a class, you need to show this code to your teacher or get a tutor. If you aren''t taking a class, then take one!

You clearly do not understand object-oriented programming. In this style of programming, you are dealing with objects, say for instance a house. Now, that house can have rooms. And it can have any number of rooms. Those rooms can have furniture...all different kinds of furniture. And that furniture can have different properties, such as fabric, color, size, etc...

This is what you''re doing here. First, you''re creating two new types of objects, income_information and record. The struct keyword tells the compiler that you are creating a new object type. Right away, though, you define income_information (using the struct keyword), then you define record and then define a new object within record, also called income_information.

You don''t use the struct keyword when you are trying to add an object to another.

In your case, record should just be:

struct record
{
  int id, number;
  char *starting_time;
  char *name;
  income_information income;
}worker[5]



但是,然后,您尝试访问income而不先访问正在处理的记录. income是另一个对象中的一个对象,因此您首先必须访问其父对象.

这就是为什么您遇到第一个错误的原因.
然后,您写income.name. incomeincome_information类型,没有名为name的属性.

至于您的main部分中的前两行,就像其他人所说的那样,它们什么也不做.

您需要首先访问每个辅助对象,然后设置该辅助对象的属性.

您也不了解指针.如果您是编程的新手,则根本不应该使用指针.他们只会使您感到困惑.在这种情况下,您不需要它们.没有指针,您可以访问工人的姓名,例如:



But then, you are trying to access income without first accessing the record you are dealing with. income is an object within another object, so you first have to access its parent.

That''s why you are getting that first error.

Then, you write income.name. income is an income_information type which has no property called name.

As to the first two lines in your main section, like others have said, they do nothing.

You need to first access each worker object and then set the properties of that worker.

You also don''t understand pointers. If you are brand new to programming, you shouldn''t be using pointers at all. They will just confuse you. And in this case, you don''t need them. Without the pointers, you could access a worker''s name like:

worker[0].name = "Jack Bauer"



要获得工人的基本工资,您需要



To access basic salary of a worker, you would want

worker[0].income.Basic_salary = 12.50;



而且,您的比较器已经插入了if语句中.您用等号切换了小于或大于符号.

应该是:



And, you have your comparators screwed up in your if statements. You switched the less than or greater than signs with the equal signs.

It should be:

if(i<=15)



另外,您无法像以前一样进行双重比较,需要使用&&比较器.

例如,如果您写:



Also, you can''t do a double comparison the way you did, you need to use the && comparator.

For instance, if you write:

int i = 5;
if (3<=i<=2)
{
  cout << "shouldn't get here";
}


即使5不小于或等于2,您也会收到消息.

这样做的原因是它将评估比较的第一部分(3<=i).这将返回true. true的整数值为1.因此,它求值第二部分为true<=2.由于true = 1,true小于或等于2.

应该是


you will get the message, even though 5 is not less than or equal to 2.

The reason for this is that it will evaluate the first part of the comparison (3<=i). This will return true. true has an integer value of 1. So, then it evaluates the second part which would be true<=2. Since true = 1, true is less than or equal to 2.

It should be

if (3<=i && i<=2)





认真地上课或找老师.





Seriously, take a class or get a tutor.


这篇关于解决先生问题PLZ ???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆