//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!
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
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
usingnamespace 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 =