so im only learning c since im fairly new and i would like to translate this code to c++ so that i could study it for future reference, all your help is highly appreciated
#include<stdio.h>
#include<conio.h>
void main(){
int poly[100], m, r, i, q[100];
printf("\t\tSYNTHETIC DIVISION");
printf("\n Enter the highest degree of the equation (max 5): ");
scanf("%d",&m);
for(i=0;i<=m;i++){
printf("\n Coefficient x[%d] = ", m-i);
scanf("%d",&poly[i]);
}
printf("\n Enter the value of constant in (x-r) : ");
scanf("%d",&r);
q[0] = poly[0];
for(i=1;i<=m;i++){
q[i] = (q[i-1]*r)+poly[i];
}
printf("\n Coefficients of quotient are: \n");
for(i=0;i<m;i++){
printf("\t%d",q[i]);
}
printf("\n Remainder is: %d", q[m]);
getch();
}
#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
vector<int> poly, q;
int m, r, i;
std::cout<<"\t\tSYNTHETIC DIVISION"<<"\n Enter the highest degree of the equation (max 5): ";
std::cin>> m;
for(i=0;i<=m;i++){
std::cout<<"\n Coefficient x["<< m-i <<"] = ";
int temp;
std::cin>> temp;
poly.push_back(temp);
}
std::cout<<"\n Enter the value of constant in (x-r) : ";
std::cin>> r;
q.push_back(poly[0]);
for(i=1;i<=m;i++){
q.push_back((q[i-1]*r)+poly[i]);
}
std::cout<<"\n Coefficients of quotient are: \n";
for(i=0;i<m;i++){
std::cout<<"\t"<< q[i];
}
std::cout<<"\nRemainder is: "<< q[m];
getch();
}
also its not very clean so dont use this as a guide to writing good c++ code
Cpp1.cpp
c:\users\plsprt\desktop\craps\cpp1.cpp(6) : error C2065: 'vector' : undeclared identifier
c:\users\plsprt\desktop\craps\cpp1.cpp(6) : error C2062: type 'int' unexpected
c:\users\plsprt\desktop\craps\cpp1.cpp(16) : error C2065: 'poly' : undeclared identifier
c:\users\plsprt\desktop\craps\cpp1.cpp(16) : error C2228: left of '.push_back' must have class/struct/union type
c:\users\plsprt\desktop\craps\cpp1.cpp(21) : error C2065: 'q' : undeclared identifier
c:\users\plsprt\desktop\craps\cpp1.cpp(21) : error C2228: left of '.push_back' must have class/struct/union type
c:\users\plsprt\desktop\craps\cpp1.cpp(21) : error C2109: subscript requires array or pointer type
c:\users\plsprt\desktop\craps\cpp1.cpp(23) : error C2228: left of '.push_back' must have class/struct/union type
c:\users\plsprt\desktop\craps\cpp1.cpp(23) : error C2109: subscript requires array or pointer type
c:\users\plsprt\desktop\craps\cpp1.cpp(23) : error C2109: subscript requires array or pointer type
c:\users\plsprt\desktop\craps\cpp1.cpp(28) : error C2109: subscript requires array or pointer type
c:\users\plsprt\desktop\craps\cpp1.cpp(30) : error C2109: subscript requires array or pointer type
c:\users\plsprt\desktop\craps\cpp1.cpp(32) : error C2065: 'getch' : undeclared identifier
c:\users\plsprt\desktop\craps\cpp1.cpp(33) : warning C4508: 'main' : function should return a value; 'void'return type assumed
Error executing cl.exe.
Cpp1.obj - 13 error(s), 1 warning(s)
#include<iostream>
#include<stdio.h>
#include<conio.h>
usingnamespace std;
main(){
int poly[100], m, r, i, q[100];
cout<<"\t\tSYNTHETIC DIVISION";
cout<<"\n Enter the highest degree of the equation (max 5):";
cin>>m;
for(i=0;i<=m;i++){
cout<<"\n Coefficient x["<<m-i<<"] = ";
cin>>poly[i];
}
cout<<"\n Enter the value of constant in (x-r) : ";
cin>>r;
q[0] = poly[0];
for(i=1;i<=m;i++){
q[i] = (q[i-1]*r)+poly[i];
}
cout<<"\n Coefficients of quotient are: \n";
for(i=0;i<m;i++){
cout<<"\t"<<q[i];
}
cout<<"\n Remainder is: "<<q[m];
getch();
return 0;
}
EDIT: GOT IT TO WORKED PROLERPLY JUST NEED SOME CLEANING ^^ thanks all
The second loop values from q and poly, even though those values are uninitialized, undefined, unknown. The result of the equation is not stored anywhere.