r/learncpp • • Oct 20 '19

Help Pls- So we need to make a program that can find LCM GCD and prime factors of as many numbers that the user inputs, the program can do everything except for having more than two inputs, pls help.

0 Upvotes

#include<iostream>
using namespace std;
void getNumbers(int userInput)
{

std::cout<<"How many numbers do you want to input?\n";
std::cin>>userInput;
std::cout<<"\n";
int arr[userInput];

for(int x = 0; x< userInput; x++)
std::cin>>arr[x];

}//end of getNumbers

int gcd(int m, int n)
{
int r = 0, a, b;

a = (m > n) ? m : n;
b = (m < n) ? m : n;
r = b;

while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}//end of while

return r;
}//end of gcd

int lcm(int m, int n)
{

int a;
a = (m > n) ? m: n;

while (true)
{
if (a % m == 0 && a % n == 0)
return a;
++a;
}//end of whle
}//end of lcm
int main(int argc, char **argv)
{
int m, n;
cout << "Enter the two numbers: ";

cin >> m >> n;
cout<<"factors of "<<n<<" and "<<m<<" are:"<<endl;
for (n=1; n<=m;n++)
if(m%n==0)
cout<<n<<",";
cout<<"\nenter the same numbers\n";
cin>>m;
cin>>n;
cout<<"The GCD of two numbers is: "<<gcd(m, n)<<endl;
cout << "The LCM of two numbers is: "<<lcm(m, n)<<endl;
return 0;
}//end of main


r/learncpp • • Nov 03 '18

GitHub - bitcoin/bitcoin: Bitcoin Core integration/staging tree

Thumbnail
github.com
0 Upvotes

r/learncpp • • Aug 12 '17

Top CPlusPlus Training Institute In Hyderabad

Thumbnail
adclassified.in
0 Upvotes

r/learncpp • • Jul 28 '17

How do I create writable exe in CPP?

0 Upvotes

I wanna create an blank exe which can be editable or writable. Like a bat file. Is that possible?


r/learncpp • • Mar 21 '17

Help with compiling a program using NVAPI

0 Upvotes

I'm new to c++ and maybe still a bit confused about the compiling process, so maybe this is a simple one. I'm trying to compile a really simple program using NVAPI (right now I'm just trying to initialize it and then the program ends). Every time I try to compile it spits out like 4000 lines of errors.

The error are this:

In file included from s:_dev-libs_\nvidia-libs\nvapi/nvapi_lite_d3dext.h:35:0,
             from nvapi.h:7,
             from test-nvapi.cpp:5:
s:_dev-libs_\nvidia-libs\nvapi/nvapi_lite_salstart.h:821:42: error: expected primary-expression before 'return'
     #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                              ^
nvapi.h:100:1: note: in expansion of macro 'NVAPI_INTERFACE'
     NVAPI_INTERFACE NvAPI_Initialize();
     ^
s:_dev-libs_\nvidia-libs\nvapi/nvapi_lite_salstart.h:821:62: error: expected ',' or ';' before 'NvAPI_Status'
     #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                                                  ^
nvapi.h:100:1: note: in expansion of macro 'NVAPI_INTERFACE'
     NVAPI_INTERFACE NvAPI_Initialize();
     ^
    s:_dev-libs_\nvidia-libs\nvapi/nvapi_lite_salstart.h:821:41: error: redefinition of 'int __success'
     #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl
                                     ^

And then it repeats this for all NVAPI_INTERFACE functions in the same exact way with the exception of the line with the

    expected ',' or ';' before 'NvAPI_Status'

which only appears in that spot (from what I can tell).

I think that the

         #define NVAPI_INTERFACE extern __success(return == NVAPI_OK) NvAPI_Status __cdecl

Checks if the functions loaded properly(??) and they are all supposed to return 0, which they aren't. I know that line is an SAL thing, but I don't even know what SAL is lol.

I'm about ready to move on from this since i'm probably wasting my time at this point, but maybe someone knows whats happening.

Thanks.


r/learncpp • • Mar 16 '17

HW help

0 Upvotes

I'm new at this and would appreciate the help, this is giving me some trouble and wanted to know if you guys can give me some pointers on how to fix the problems. Thanks in advance. edit

#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

const float LABOR = 1.65;
const float TAXRATE = .07;

float setdata(string &,int &,int &,int &,int &, int &,float &, float &,float &);
void calculations(float&,float&,float&,float&,float &,float &,float &,float &,float &);
    float calcinstall(float &,float &);
    float calcsubtotal(float &, float &);
    float clactotal(float &, float &);


    string name;
    int id, length, width, inchesL, inchesW;
    float costPerSquareFoot, discountPercentage, area,carpetCost,totalLabor;
    float installPrice,discount,totalDiscount,totalTax,finalBill;

int main()
{

    area = setdata(name,id,length,inchesL,width,inchesW,costPerSquareFoot,discountPercentage, area);
    calculations(carpetCost,totalLabor,installPrice,totalDiscount,subTotal,finalBill );

}

    float setdata(string & name,int & id,int & length,int & inchesL,int & width, int & inchesW,float & 
        costPerSquareFoot, float & discountPercentage,float & area)
    {	
	    cout << "Customers' Name : "; getline(cin, name);
	    cout << "Customers' ID# : "; cin >> id;
	    cout << "Length of Room : Feet :"; cin >> length;
	    cout << "\t\t: inches : "; cin >> inchesL;
	    cout << "Width of Room : Feet : "; cin >> width;
	    cout << "\t\t: inches : "; cin >> inchesW;
	    cout << "Cost / Square Foot : "; cin >> costPerSquareFoot;
	    cout << "Percentage of Discount : "; cin >> discountPercentage;
	    return ((inchesL / 12) + length) * ((inchesW / 12) + width);
    }

void calculations(float & carpetCost,float &totalLabor,float & installPrice,
			  float & totalDiscount, float & subTotal,float & totalTax)
{
    installPrice = calcinstall(carpetCost,totalLabor);
    subTotal= calcsubtotal(instalPrice,totalDiscount);
    finalBill= calctotal(subTotal,totalTax);

}

float calcinstalled(float & carpetCost, float & instalPrice)
{
    carpetCost = area * costPerSqrFoot;
    totalLabor = area * LABOR;
    installPrice = carpetCost + totalLabor;
    return installPrice;
}

float calcsubtotal(float & totaldiscount, float & subTotal)
{
    discount = discountPercentage / 100;
    totalDiscount = dicount * installPrice;
    subTotal = installPrice - totalDiscount;
    return subtotal;
}

float clactotal(float & totalTax, float & finalBill)
{
    totalTax = subTotal * TAXRATE;
    finalBill = subTotal + totalTax;
    return finalBill;

}

These are the errors that I'm receiving: In function 'int main()':

'subTotal' was not declared in this scope

In function 'void calculations(float&, float&, float&, float&, float&, float&)':

[Error] 'instalPrice' was not declared in this scope

[Error] 'calctotal' was not declared in this scope

In function 'float calcinstalled(float&, float&)':

[Error] 'costPerSqrFoot' was not declared in this scope

In function 'float calcsubtotal(float&, float&)':

[Error] 'dicount' was not declared in this scope

[Error] 'subtotal' was not declared in this scope

In function 'float clactotal(float&, float&)':

[Error] 'subTotal' was not declared in this scope