Student, Need Help!

//Homework assignement 1 question 3

#include<iostream>
using namespace std;

int main()
{
int A;
int B;
int C;
int D;

cout<<"Enter a number for A";
cin>>A;
cout<<"Enter a number for B";
cin>>B;
cout<<"Enter a number for C";
cin>>C;
cout<<"Enter a number for D";
cin>>D;

cout<<"When your numbers are applied to the formula a(b+c)–d^3 you get";
cout<< A*(B+C)-D^3 <<;

system("pause");
}


Getting Error: "expected primary expression before ";" token
on line 23 that error is
cout<< A*(B+C)-D^3 <<;
should be cout<< A*(B+C)-D^3;
23 C:\DOCUME~1\Steven\LOCALS~1\Temp\C++ 3 start.cpp no match for 'operator^' in '(&std::cout)->std::basic_ostream<_CharT, _Traits>::operator<< [with _CharT = char, _Traits = std::char_traits<char>]((((B + C) * A) - D)) ^ 3'

note C:\Dev-Cpp\include\c++\3.4.2\bits\ios_base.h:67 candidates are: std::_Ios_Fmtflags std::operator^(std::_Ios_Fmtflags, std::_Ios_Fmtflags)

note C:\Dev-Cpp\include\c++\3.4.2\bits\ios_base.h:67 std::_Ios_Openmode std::operator^(std::_Ios_Openmode, std::_Ios_Openmode)

note C:\Dev-Cpp\include\c++\3.4.2\bits\ios_base.h:67 std::_Ios_Iostate std::operator^(std::_Ios_Iostate, std::_Ios_Iostate)

I get those notes and errors when I fixed it
Hi, the error happens because of D^3. To raise a power, I think you can use pow(double (D),3), but to use this you have to include #include <math.h>

More information about power can be found here: http://www.cplusplus.com/reference/cmath/pow/
Well i use turbo c++.I would have never used "using namespace std". But first try adding <stdlib.h> header and <math.h> and then
cout<< A*(B+C)-D^3 <<; should be
cout<< A*(B+C)-pow(D,3) ;
Last edited on
how would i incorporate that into my formula so that it works properly?
Hi, i have edited your code. Hope this helps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int A;
	int B;
	int C;
	int D;

	cout<<"Enter a number for A: ";
	cin>>A;
	cout<<"Enter a number for B: ";
	cin>>B;
	cout<<"Enter a number for C: ";
	cin>>C;
	cout<<"Enter a number for D: ";
	cin>>D;

	cout<<"When your numbers are applied to the formula a(b+c)–d^3 you get: ";
	cout<< A*(B+C)-pow(double(D),3) << endl; //for pow(double base, double exponent). 
                                         //So you need to change your D from int to double

	system("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.