Post: C++ problem help
03-28-2013, 01:55 AM #1
silverdollar
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({});
    
#include <isostream>
#include <math>
#include <stdlib>

int main()
{
using namespace std;

int selection(0);
double input1(0.0);
double input2(0.0);
char indicator('n'Winky Winky;

cout << "Welcome to the C++ Calculator" << end1;

for (;Winky Winky
{
cout << "please choose the operation that you want: "
<< end1
<< "1 addition" << end1
<< "2 subtraction" << end1
<< "3 multiply" << end1
<< "4 division" << end1
<< "5 square root" << end1
<< "6 power" << end1
<< "0 exit" << end1
<< end1
<< "enter your selection number: ";

cln >> selection;

switch (selection)
{
case 1: cout << end1 << "enter the frist number to add: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the sum of" << input1 << " and " << input2 << " is " << input + input2 << end1;
break;

case 2: cout << end1 << "enter the frist number to subtract: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the difference between" << input1 << " and " << input2 << " is " << input - input2 << end1;
break;

case 3: cout << end1 << "enter the frist number to multiply: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the product of" << input1 << " and " << input2 << " is " << input * input2 << end1;
break;

case 4: cout << end1 << "enter the frist number to divide: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the quotient of" << input1 << " and " << input2 << " is " << input / input2 << end1;
break;

case 5: cout << end1 << "enter the number you want to find the square root of: ";
cln >> input;
cout << end1 << "the square root of" << input1 << " is " << sqrt(input1) << end1;
break;

case 6: cout << end1 << "enter the base: ";
cln >> input;
cout << end1 << "enter the exponent: ";
cln >> input2;
cout << end1 << input1 << "to the power of" << input2 << "is equal to" << pow(input1, input2) << end1;
break;

case 0: exit(exit_success);
break;

default: cout << end1 << "the selection number you have entered is invalid" << end1;
break;
}
cout << end1 << "would you like to perform another calculation? (y or n): ";
cln >> indicator;

if((indicator == "n") || (indicator == "n"))
break;

}

return 0;
}


can someone tell me what i did wrong because i cant figure it out or did i save the file wrong or what becuse the program isnt opening.

---------- Post added at 08:55 PM ---------- Previous post was at 08:53 PM ----------

it was high lighting the using namespace std; saying something wrong with it maybe its something else to though because idk
(adsbygoogle = window.adsbygoogle || []).push({});
03-28-2013, 01:59 AM #2
Originally posted by silverdollar View Post
#include <isostream>
#include <math>
#include <stdlib>

int main()
{
using namespace std;

int selection(0);
double input1(0.0);
double input2(0.0);
char indicator('n'Winky Winky;

cout << "Welcome to the C++ Calculator" << end1;

for (;Winky Winky
{
cout << "please choose the operation that you want: "
<< end1
<< "1 addition" << end1
<< "2 subtraction" << end1
<< "3 multiply" << end1
<< "4 division" << end1
<< "5 square root" << end1
<< "6 power" << end1
<< "0 exit" << end1
<< end1
<< "enter your selection number: ";

cln >> selection;

switch (selection)
{
case 1: cout << end1 << "enter the frist number to add: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the sum of" << input1 << " and " << input2 << " is " << input + input2 << end1;
break;

case 2: cout << end1 << "enter the frist number to subtract: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the difference between" << input1 << " and " << input2 << " is " << input - input2 << end1;
break;

case 3: cout << end1 << "enter the frist number to multiply: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the product of" << input1 << " and " << input2 << " is " << input * input2 << end1;
break;

case 4: cout << end1 << "enter the frist number to divide: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the quotient of" << input1 << " and " << input2 << " is " << input / input2 << end1;
break;

case 5: cout << end1 << "enter the number you want to find the square root of: ";
cln >> input;
cout << end1 << "the square root of" << input1 << " is " << sqrt(input1) << end1;
break;

case 6: cout << end1 << "enter the base: ";
cln >> input;
cout << end1 << "enter the exponent: ";
cln >> input2;
cout << end1 << input1 << "to the power of" << input2 << "is equal to" << pow(input1, input2) << end1;
break;

case 0: exit(exit_success);
break;

default: cout << end1 << "the selection number you have entered is invalid" << end1;
break;
}
cout << end1 << "would you like to perform another calculation? (y or n): ";
cln >> indicator;

if((indicator == "n") || (indicator == "n"))
break;

}

return 0;
}


can someone tell me what i did wrong because i cant figure it out or did i save the file wrong or what becuse the program isnt opening.

---------- Post added at 08:55 PM ---------- Previous post was at 08:53 PM ----------

it was high lighting the using namespace std; saying something wrong with it maybe its something else to though because idk



just rushed through it but.. cout << "Welcome to the C++ Calculator" << end1; end1 is undeclared and idk if you're typing CLN or what but it should be cin as in "console in" umm theres a lot of logic errors. I think you should carefully revise the way you wrote this.
03-28-2013, 03:30 AM #3
Pure Decimation
I don't do requests
#include <iostream>
#include <cmath>

int main()
{
using namespace std;

int selection(0);
double input1(0.0);
double input2(0.0);
char indicator('n'Winky Winky;

cout << "Welcome to the C++ Calculator" << endl;

for(;Winky Winky
{
cout << "please choose the operation that you want: "
<< endl
<< "1 addition" << endl
<< "2 subtraction" << endl
<< "3 multiply" << endl
<< "4 division" << endl
<< "5 square root" << endl
<< "6 power" << endl
<< "0 exit" << endl
<< endl
<< "enter your selection number: ";

cin >> selection;

switch (selection)
{
case 1: cout << endl << "enter the first number to add: ";
cin >> input1;
cout << endl << "enter the second number: ";
cin >> input2;
cout << endl << "the sum of" << input1 << " and " << input2 << " is " << input1 + input2 << endl;
break;

case 2: cout << endl << "enter the first number to subtract: ";
cin >> input1;
cout << endl << "enter the second number: ";
cin >> input2;
cout << endl << "the difference between" << input1 << " and " << input2 << " is " << input1 - input2 << endl;
break;

case 3: cout << endl << "enter the first number to multiply: ";
cin >> input1;
cout << endl << "enter the second number: ";
cin >> input2;
cout << endl << "the product of" << input1 << " and " << input2 << " is " << input1 * input2 << endl;
break;

case 4: cout << endl << "enter the first number to divide: ";
cin >> input1;
cout << endl << "enter the second number: ";
cin >> input2;
cout << endl << "the quotient of" << input1 << " and " << input2 << " is " << input1 / input2 << endl;
break;

case 5: cout << endl << "enter the number you want to find the square root of: ";
cin >> input1;
cout << endl << "the square root of" << input1 << " is " << sqrt(input1) << endl;
break;

case 6: cout << endl << "enter the base: ";
cin >> input1;
cout << endl << "enter the exponent: ";
cin >> input2;
cout << endl << input1 << "to the power of" << input2 << "is equal to" << pow(input1, input2) << endl;
break;

case 0: return 0;
break;

default: cout << endl << "the selection number you have entered is invalid" << endl;
break;
}
cout << endl << "would you like to perform another calculation? (y or n): ";
cin >> indicator;

if((indicator == 'n'Winky Winky || (indicator == 'n'Winky Winky)
break;

}

return 0;
}


There you go sir. Corrected a few things. Your primary problems were you includes. You had isostream where it should have read iostream and math where you needed cmath. You do not need an stdlib include as you do not use the features of it. You cin's were cln's and endl's were end1's. I also change your exit("exit_success") to a simple return 0. No need for an exit command there as a return will functionally do the same thing. (Also I couldn't remember the proper syntax for it and yours was incorrect.) I think that's about it though.
04-01-2013, 03:25 PM #4
Master Ro
I make food
Originally posted by silverdollar View Post
    
#include <isostream>
#include <math>
#include <stdlib>

int main()
{
using namespace std;

int selection(0);
double input1(0.0);
double input2(0.0);
char indicator('n'Winky Winky;

cout << "Welcome to the C++ Calculator" << end1;

for (;Winky Winky
{
cout << "please choose the operation that you want: "
<< end1
<< "1 addition" << end1
<< "2 subtraction" << end1
<< "3 multiply" << end1
<< "4 division" << end1
<< "5 square root" << end1
<< "6 power" << end1
<< "0 exit" << end1
<< end1
<< "enter your selection number: ";

cln >> selection;

switch (selection)
{
case 1: cout << end1 << "enter the frist number to add: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the sum of" << input1 << " and " << input2 << " is " << input + input2 << end1;
break;

case 2: cout << end1 << "enter the frist number to subtract: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the difference between" << input1 << " and " << input2 << " is " << input - input2 << end1;
break;

case 3: cout << end1 << "enter the frist number to multiply: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the product of" << input1 << " and " << input2 << " is " << input * input2 << end1;
break;

case 4: cout << end1 << "enter the frist number to divide: ";
cln >> input;
cout << end1 << "enter the second number: ";
cln >> input2;
cout << end1 << "the quotient of" << input1 << " and " << input2 << " is " << input / input2 << end1;
break;

case 5: cout << end1 << "enter the number you want to find the square root of: ";
cln >> input;
cout << end1 << "the square root of" << input1 << " is " << sqrt(input1) << end1;
break;

case 6: cout << end1 << "enter the base: ";
cln >> input;
cout << end1 << "enter the exponent: ";
cln >> input2;
cout << end1 << input1 << "to the power of" << input2 << "is equal to" << pow(input1, input2) << end1;
break;

case 0: exit(exit_success);
break;

default: cout << end1 << "the selection number you have entered is invalid" << end1;
break;
}
cout << end1 << "would you like to perform another calculation? (y or n): ";
cln >> indicator;

if((indicator == "n") || (indicator == "n"))
break;

}

return 0;
}


can someone tell me what i did wrong because i cant figure it out or did i save the file wrong or what becuse the program isnt opening.

---------- Post added at 08:55 PM ---------- Previous post was at 08:53 PM ----------

it was high lighting the using namespace std; saying something wrong with it maybe its something else to though because idk


~Added code tags and moved to Computer Programming and Coding Questions.
04-02-2013, 09:20 PM #5
SC-Wotan
Do a barrel roll!
1. <cmath> and not <math>

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo