Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-20-2005, 09:27 PM   #1 (permalink)
tloc
Registered User
 
Join Date: Mar 2005
Posts: 3
tloc is on a distinguished road
noob needs some help

hello i am new to c++ and need some help on this code i want the user to choose an operator but can't figure how to do that the rest i think i got any help would be appreciated or sugestions.
Code:
#include <iostream>
using namespace std;
int main()
{
	int num1,num2;
    
	
	cout<< "Enter 2 integers:"<<endl;
	cin >> num1>>num2;
	cout<< "enter operator: + (addition),-(subtraction),* (multiplication),/(division):"<<endl;
	cin >>  +-* /;
      
    cout << "Sum is " << (num1 + num2) << endl;
    cout << "Quotient is " << (num1 / num2) << endl;
	cout << "Remainder is " << (num1 % num2) << endl;
    cout<< "product is " << (num1 * num2) << endl;
	return 0;

}
tloc is offline   Reply With Quote
Old 03-20-2005, 11:22 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
cin >> +-* /; this is just wrong, you can't read a given value into an operator.
something like this might do the trick: (hasn't been tested, not even compiled)
Code:
#include <iostream>
using namespace std;
int main()
{
             int num1,num2;    // numbers to operate on
             char operator[2]; // make room for operator plus <cr>
	
             cout << "Enter 2 integers:"<<endl;
             cin >> num1 >> num2;
             cout << "enter operator: + (addition),-(subtraction),* (multiplication),/(division), %(remainder):" << endl;
             cin.getline(operator, 2, '\n' );
             switch((int)operator[0])
             {
                 case '+':
                      cout << "Sum is " << (num1 + num2) << endl;
                     break;
                 case '/':
                      cout << "Quotient is " << (num1 / num2) << endl;
                 case '%':
                      cout << "Remainder is " << (num1 % num2) << endl;
                      break;
                 case '*':
                      cout<< "product is " << (num1 * num2) << endl;
                      break;
                 default:
                       cout << "Don't know how to use operator " << operator << endl;
              }
	return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-21-2005, 08:08 AM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Basically this:
Code:
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
  int num1,num2;    // numbers to operate on
  char Operator;
  cout << "Enter 2 integers:"<<endl;
  cin >> num1 >> num2;
  cout << "enter operator: + (addition),-(subtraction),* \

    (multiplication),/(division), %(remainder):" << endl;

  cin>>Operator;
  switch(Operator)
  {
    case '+':
    cout << "Sum is " << (num1 + num2) << endl;  break;
    case '/':
    cout << "Quotient is " << (num1 / num2) << endl; break;
    case '%':
    cout << "Remainder is " << (num1 % num2) << endl; break;
    case '*':
    cout<< "product is " << (num1 * num2) << endl; break;
    default:
    cout << "Don't know how to use operator " << Operator << endl;
  }

  return 0;
}
__________________
Valmont is offline   Reply With Quote
Old 03-21-2005, 11:07 AM   #4 (permalink)
tloc
Registered User
 
Join Date: Mar 2005
Posts: 3
tloc is on a distinguished road
thanks guys i now know what i did wrong
tloc is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help im a noob CaN Opener PHP 4 10-10-2003 04:15 PM
true noob Odoggy5 PHP 5 08-22-2003 01:46 PM


All times are GMT -8. The time now is 07:35 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting