error C2440: '=' : cannot convert from 'char [15]' to 'char'

Hi!
I'm reza.
I am writting this program:
.
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
//Just a test for: IF IF..ELSE FOR WHILE DO..WHILE;
#include <iostream.h>
#include <conio.h>
int main(){

	cout<<"\n plz enter an order ...";
	char order;
	cin>>order;
	if(order="get 10 numbers"){
		int i, num[10];
		for(i=1;i<=10;i++){
			cout<<"Please enter the "<<i<<"th number ... ";
			cin>>num[i];}
		cout<<"Ok!"
			<<"You've entered 10 numbers"
			<<"Now what is the point ? ... ";
		order=0;
		cin>>order;
		if(order='sum'){
			int sum=0;
			while(i<=10){
				i++;
				sum +=num[i];}
			cout<<"Here you go! ... this is the result ... ";
			cout<<sum;
		}
	}
}

.
Because of the first error i didn't finish the code.
It gives me that error related to the first if.
can you solve it?
Thanks!
order is a single character. "get 10 numbers" is a string of characters. You can't compare them.
Though you are using =, not ==, in your if() check.
char order should be char order[20] - doesn't have to be 20 but should be big enough to hold the text. And if(order="get 10 numbers") should be if(strcmp(order, "get 10 numbers") == 0). Comparing char arrays or char pointers or any pointers with == will check whether their memory address are the same. You should also note that you used a = as opposed to == which will assign order to that string not compare them
char order should be char order[20]


Scratch that.

Use strings until you better understand arrays and dynamic memory (and even after, since strings are generally safer/easier/less error prone):

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>  // NOT iostream.h
#include <string>  // for string

using namespace std;

int main()
{
	cout<<"\n plz enter an order ...";
	string order;  // make this a string, not a char
	getline(cin,order);  // use getline instead of >>
	if(order=="get 10 numbers"){  // use == instead of = 


}
Topic archived. No new replies allowed.