complete begginer to programming and C++

April 15, 2011 at 17:50:46
Specs: Windows 7
Error: ISO C++ forbids comparison between pointer and integer


#include <iostream>
using namespace std;

class Multiplication{
public:
void multiply(){
int a;
int b;
int product;

cout << "Enter a number: ";
cin >> a;
cout << "Enter a second number to multiply by " << a << ": ";
cin >> b;

product = a * b;

cout << a << "*" << b << "=" << product;
}

};

int main()
{
int whatnow;
Multiplication Multiply;
cout << "What would you like to do? \n" " Enter + - * or / : " << endl;
cin >> whatnow;
if(whatnow=="*"){

Multiply.multiply();
};
return 0;
}
___________________________________________________________________________
basically im trying to make it so the user can input what they want to do as in multiply, and i keep getting errors here. once i can finish the multiplication part, i can assign it to all others with ease.


See More: complete begginer to programming and C++

Report •

#1
April 15, 2011 at 18:28:39
int whatnow;
Should be
char whatnow;

if(whatnow=="*"){
Should be

if(whatnow=='*'){

How To Ask Questions The Smart Way


Report •

#2
April 15, 2011 at 19:47:12
Thank you so much. now whats the difference between char and int? and how do i know when to use char instead of int?

Report •

#3
April 15, 2011 at 21:22:32
whats the difference between char and int?
int is an integer. char is a character. If you want to hold a number (for use in, say, multiplication), use int. If you want to hold a character (for, say, general user input), use char.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
April 15, 2011 at 23:22:41
Also, keep this discussion to one thread. The duplicate has been removed.

EDIT: And while we're on the subject, why are you placing each method in an otherwise empty class?

How To Ask Questions The Smart Way


Report •

#5
April 16, 2011 at 06:28:46
Well im quite new to c++ and I havent learned much about it yet (not even while loops). Also I could use help with that previous problem, it wasnt a duplicate it was a totally different question, because I cannot figure out how to set up the next part for addition. Am I not allowed to use multiple ifs without closing the 1st one?

Report •

#6
April 16, 2011 at 07:12:20
Different question, but same program.

Am I not allowed to use multiple ifs without closing the 1st one?
No, you're allowed to nest ifs.

How To Ask Questions The Smart Way


Report •

Ask Question