Struct problem

Hi
My English is bad.So i make excuse for false understanding right now.I have a problem with about structs.My problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <iostream>

using namespace std;

struct Datas{
string *Name;
string *Surname;
unsigned char *Choose[120];
int a;
int b;
int c;
}
int main(){

cout<<"Name:";
cin>>Name;
cout<<"Surname:";
cin>>Surname;
cout<<"Dear"<<Name<<Surname<<"Choose your a transaction:";
if(Choose=='Adding')
{
 cout<<"Dear"<<Name<<Surname<<"Choose your numbers for adding";
 cin>>a;
 cin>>b;
 c=a+b;
 cout<<"Your adding result:"<<c;
}
return 0;
}


I am taking 2 errors when i build these code:

error:new types may not be defined in a return type
error:two or more data types in declaration of 'main'

These are error message.I am grateful for your helps already.
I want to be add on this:I am using Code Blocks
These lines don't work:
1
2
cin >> Name;
cin >> Surname;


You haven't declared those variables anywhere before trying to use them. My *guess* is that you are trying to reference the 2 string members of your struct. Go back and study how to use structs again then give it another shot. Ask if you come across a part that you don't fully understand. Ask specific questions.
Both reported errors have the same cause.

Line 13 you forgot the semicolon after the closing brace on your Datas structure which makes it look to the compiler as though main was declared as Datas int main(), i.e., two return types. Assuming as sadavied suggested that your lines referencing Name and Surname were intended to reference the struct members, you would need to reference them using the dot operator, but you never actually instantiated a variable of type Datas.

Also, I suspect you wanted Name and Surname to be strings and not pointers to strings.

Line 21 single quotes are for use with single character literals only.
Last edited on
Hi,
I tried Alrededor say Datas int main() method.And i took this error message in the
line 14 : expected initializer before 'int'
That's already been explained to you, add a semicolon after your struct definition
I resolved my problem presumably.But i take just-in-time debugger error when i run these code.

I tailored my codes in http://www.cplusplus.com/doc/tutorial/structures codes.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  int result;
  char *Transaction;
  string Name;
  string Surname;
  int a,b,c;
} mine;

void printmovie (movies_t movie);
int d;
int main ()
{
  string mystr;
cout<<"Name:";
  cin>>mine.Name;
  cout<<"Surname:";
  cin>>mine.Surname;
  cout<<"U write to want ur transaction:";
  cin>>mine.Transaction;
  if(mine.Transaction=="Adding"){
  cout<<"First number:";
  cin>>mine.a;
  cout<<"Second number";
  cin>>mine.b;
  mine.c=mine.a+mine.b;
  d=mine.c;
  }
  else{
  cout<<"Wrong transaction";
  }
  printmovie(mine);
return 0;
}

void printmovie (movies_t movie)
{
    movie.result=d;
  cout << "Your transaction result="<<movie.result;
}
I passed my all blocks.And i found a func.
My codes end affair:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
using namespace std;

struct movies_t {
  int result;
  char *Transaction;
  string Name;
  string Surname;
  int a,b,c;
} mine;

void printmovie (movies_t movie);
int d;
int main ()
{
  string mystr;
cout<<"Name:";
  cin>>mine.Name;
  cout<<"Surname:";
  cin>>mine.Surname;
  cout<<"U write to want ur transaction:";
  cin>>mine.Transaction;
  if(strcmp(mine.Transaction,"Adding")){
  cout<<"First number:";
  cin>>mine.a;
  cout<<"Second number";
  cin>>mine.b;
  mine.c=mine.a+mine.b;
  d=mine.c;
  }
 
 else{
  cout<<"Wrong transaction";
 exit(1);
 }
  printmovie(mine);
return 0;
}

void printmovie (movies_t movie)
{
    movie.result=d;
  cout << "Your transaction result="<<movie.result;
}


U could help me more.Anyway all thanks.
Last edited on
Topic archived. No new replies allowed.