Help with my program(errors)


Alright I have just started using C++ recently so am doing these sort of programs. I am not finished this one yet but there are a few errors I do not know how to fix. Ill list the errors below the code.




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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "stdafx.h"
#include <cmath>

using namespace System;

float add_func(float);
float sub_func(float);
float mult_func(float);
float div_func(float);
float end_func(float);

int main(array<System::String ^> ^args)
{
    float add1;
	float sub1;
	float mult1;
	float div1;
	float x;
	float t = 0;

while t = 0;
{

	Console::WriteLine("Please Choose an option:\n");
	Console::WriteLine("1: Addition\n2: Subtraction\n3: Multiplication\n4: Division\n5: Exit\n");
	x = Convert::ToInt16(Console::ReadLine());

if (x > 0 && x < 6)
{
	if (x == 1);
	{
		add1++;
		add_func();
	}
	
	if (x == 2);
	{
		sub1++;
		sub_func();
	}
	
	if (x == 3);
	{
		mult1++;
		mult_func();
	}
	
	if (x == 4);
	{
		div1++;
		div_func();
	}
	
	if (x == 5);
	{
		end_func;
	}


	Console::WriteLine("\n\n\nTimes used:\nAddition:"+add1+"\nSubtraction:"+sub1+"\nMultiplication:"+mult1+"\nDivision:"+div1);
}
}
    return 0;
}

float add_func(float)
{
	float ax;
	float ay;
	float an;

	Console::WriteLine("Please enter the two numbers you would like added");
	Console::WriteLine("First number: ");
	ax = Console::ReadLine();
	Console::WriteLine("Second number: ");
	ay = Console::ReadLine();

	an = ax + ay;

	Console::WriteLine("The answer is: "+an);
	return 0;
}

float sub_func(float)
{
	float sx;
	float sy;
	float sn;

	Console::WriteLine("Please enter the two numbers you would like added");
	Console::WriteLine("First number: ");
	sx = Console::ReadLine();
	Console::WriteLine("Second number: ");
	sy = Console::ReadLine();
	
	sn = sx - sy;

	Console::WriteLine("The answer is: "+sn);
	return 0;
}

float mult_func(float)
{
	float mx;
	float my;
	float mn;

	Console::WriteLine("Please enter the two numbers you would like multiplied");
	Console::WriteLine("First number: ");
	mx = Console::ReadLine();
	Console::WriteLine("Second number: ");
	my = Console::ReadLine();
	
	mn = mx * my;

	Console::WriteLine("The answer is: "+mn);
	return 0;
}

float div_func(float)
{
	float dx;
	float dy;
	float dn;

	Console::WriteLine("Please enter the two numbers you would like divided");
	Console::WriteLine("First number: ");
	dx = Console::ReadLine();
	Console::WriteLine("Second number: ");
	dy = Console::ReadLine();
	
	dn = dx / dy;

	Console::WriteLine("The answer is: "+dn);
	return 0;
}

float end_func(float)
{

	
	return 0;
}



Errors:
Error 1 error C2061: syntax error : identifier 't' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 23

Error 3 error C2660: 'add_func' : function does not take 0 arguments c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 35

Error 5 error C2660: 'sub_func' : function does not take 0 arguments c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 41

Error 7 error C2660: 'mult_func' : function does not take 0 arguments c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 47

Error 9 error C2660: 'div_func' : function does not take 0 arguments c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 53

Error 12 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 76

Error 13 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolmi\Cdriolm\Cdriolm.cpp 78

Error 14 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 94

Error 15 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 96

Error 16 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 112

Error 17 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 114

Error 18 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 130

Error 19 error C2440: '=' : cannot convert from 'System::String ^' to 'float' c:\Documents and Settings\cdriol\My Documents\Visual Studio 2005\Projects\Cdriolm\Cdriolm\Cdriolm.cpp 132

I see now why iam getting the cannot convert to system string but there is no command that I can see where I can put in

Convert::tofloat (or something to that nature)
The first thing I saw is that you are trying to call functions that require arguments but in calling them you don't supply any arguments. That should reduce a couple of errors for you.
Ok, first of all,

while t = 0;

should be written like

while (t == 0)

without the semi-colon.
C++ requires the parenthesis for the "while" as it does for "if".
And don't forget, "=" is the assignment operator and "==" is the equality operator (easy to miss).

Secondly, as sperva described above, "you are trying to call functions that requires arguments but in calling them you don't supply any arguments".
To define a function without any arguments you can write like this:

float add_func(void)

The "void" says that no arguments should be supplied.
Also, I see that you are returning a float value of 0 from all functions. In your case that doesn't seem to be needed. To define a function that doesn't return a value you could write like this:

void add_func(void)

where the first "void" describes that no value will be returned. Therefore you can omit the "return" statement inside the function.
Hello
I am having problem with my code. I am working with VC 6.0 and using opencv
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
 // uchar *data;
  int i,j;
  
  float **mat;
  CvScalar s;

  
  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1],0);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
 // data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels %d widthStep\n",height,width,channels,width); 

  mat=malloc(height * sizeof(float*));
  
  for(i=0;i<height;i++)
  {
	  mat[i]=malloc(width * sizeof(float));
  }

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

 

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);
  
  for(i=0;i<height;i++)
  {
	  for(j=0;j<width;j++)
	  {
		  s=cvGet2D(img,i,j); // get the (i,j) pixel value
		  mat[i][j]=s.val[0];
	//printf("intensity=%f\n",s.val[0]);
	  }
  }


  // release the image
  cvReleaseImage(&img );
  return 0;
}


I am getting the following errors

H:\Work\BTP\hello_world\hello_world.cpp(39) : error C2440: '=' : cannot convert from 'void *' to 'float ** '
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
H:\Work\BTP\hello_world\hello_world.cpp(43) : error C2440: '=' : cannot convert from 'void *' to 'float *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
H:\Work\BTP\hello_world\hello_world.cpp(63) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.

hello_world.obj - 2 error(s), 1 warning(s)

Can anyone please help me
Topic archived. No new replies allowed.