Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi Purpose Calculator
#7
(10-25-2010, 12:37 PM)Reality Wrote: Is it possible in c++ to allow the person to type the sign they choose>?

Like in pythonI think you can do

print "Choose blah blah"
if input = ""
etc?

sorry for typing my lapop broke and im on a netbook

Yes, absolutely. The easiest thing would be to store the input as a char (a 1 byte data type that can store a single character such as 'a'). You could also bring in the C++ string library and store the input as a string. The string library overloads the equal to operator (==) to allow for comparing two strings.

Char
Code:
#include <iostream>

int main ()
{
  std::cout << "Enter a character: ";
  char input;
  std::cin >> input;
  
  if (input == 'a')
  {
    std::cout << "You entered the letter A." << std::endl;
  }
  
  return 0;
}

String
Code:
#include <iostream>
#include <string>

int main ()
{
  std::cout << "Enter a character: ";
  std::string input;
  std::cin >> input;
  
  if (input == "something")
  {
    std::cout << "You said something." << std::endl;
  }
  
  return 0;
}
Ho, ho, ho! Well, if it isn't fat stinking billy goat Billy Boy in poison!
How art thou, thou globby bottle of cheap, stinking chip oil?
Come and get one in the yarbles, if ya have any yarbles, you eunuch jelly thou!
Reply


Messages In This Thread
Multi Purpose Calculator - by Reality - 10-22-2010, 10:05 PM
RE: Multi Purpose Calculator - by Reality - 10-24-2010, 07:22 PM
RE: Multi Purpose Calculator - by Disease - 10-24-2010, 08:21 PM
RE: Multi Purpose Calculator - by Reality - 10-24-2010, 09:14 PM
RE: Multi Purpose Calculator - by Disease - 10-25-2010, 04:13 AM
RE: Multi Purpose Calculator - by Reality - 10-25-2010, 12:37 PM
RE: Multi Purpose Calculator - by Disease - 10-25-2010, 02:10 PM
RE: Multi Purpose Calculator - by Reality - 10-25-2010, 05:04 PM
RE: Multi Purpose Calculator - by Disease - 10-25-2010, 05:22 PM
RE: Multi Purpose Calculator - by Reality - 10-25-2010, 07:33 PM
RE: Multi Purpose Calculator - by haphazard - 10-27-2010, 07:04 PM
RE: Multi Purpose Calculator - by Hustler - 10-27-2010, 07:05 PM
RE: Multi Purpose Calculator - by Reality - 10-27-2010, 07:05 PM
RE: Multi Purpose Calculator - by Hustler - 10-27-2010, 07:11 PM
RE: Multi Purpose Calculator - by Reality - 10-27-2010, 07:25 PM
RE: Multi Purpose Calculator - by Disease - 10-27-2010, 07:23 PM
RE: Multi Purpose Calculator - by Arеs - 11-01-2010, 09:10 AM
RE: Multi Purpose Calculator - by Disease - 11-01-2010, 09:45 AM
RE: Multi Purpose Calculator - by Reality - 11-01-2010, 09:43 AM
RE: Multi Purpose Calculator - by Reality - 11-01-2010, 09:48 AM
RE: Multi Purpose Calculator - by Bursihido - 12-13-2010, 10:50 PM
RE: Multi Purpose Calculator - by Buzz Lightyear - 12-14-2010, 06:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  my own calculator WHITE PANDA 8 2,189 07-14-2010, 03:19 PM
Last Post: Kondry
  Calculator v1 Brainless Control 21 5,220 01-18-2010, 10:34 PM
Last Post: Equinøx
  Calculator in C Liberty 4 1,318 12-10-2009, 11:45 PM
Last Post: Sagittarius

Forum Jump:


Users browsing this thread: 19 Guest(s)