Help me with Ordering Number problem

I have final exams and I have to submit my assignment tomorrow please anyone can help??

question is ...

Scenario 3: Order number
Create the C++ Function named multiples so that it has two parameters x, and n. The
first parameter x will be overloaded with int, double and float. n will always be int. The
return type is void. A Function created from multiples will compute.
sum = 1 + x + 2x + 3x + ... + nx
e.g n = 4
sum = 1+x+2x+3x+4x
and display the result on screen.
I need a source code ... please or else I will fail my finals
This is a ten minute assignment. Thirty if you dawdle. If you can't solve this by tomorrow then perhaps you deserve to fail.
Hi @hemantkhada,
If I understood correctly, you wanted the code for those functions.
Here is something I would do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void multiples(int x, int n)
{
    int sum=1+(n*(n+1)/2)*x;
    std::cout<<sum;
}
void multiples(float x, int n)
{
    float nFloat=float(n);
    float sum=1+(nFloat*(nFloat+1)/2)*x;
    std::cout<<sum;
}
void multiples(double x, int n)
{
    double nDouble=double(n);
    double sum=1+(nDouble*(nDouble+1)/2)*x;
    std::cout<<sum;
}

Hope this helps.
Last edited on
Please buddy help me ... I am really in need of help right now.
If I can return this help I would love to do anything... its really very important to me. :'(
@troaat
can u complete the source code with the headers and all functions??
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
27
28
29
30
31
32
33
34
35
#include<iostream>
void multiples(int x, int n)
{
    int sum=1+(n*(n+1)/2)*x;
    std::cout<<sum;
}
void multiples(float x, int n)
{
    float nFloat=float(n);
    float sum=1+(nFloat*(nFloat+1)/2)*x;
    std::cout<<sum;
}
void multiples(double x, int n)
{
    double nDouble=double(n);
    double sum=1+(nDouble*(nDouble+1)/2)*x;
    std::cout<<sum;
}
int main()
{
    int x, n;
    float xFloat;
    double xDouble;
    std::cout<<"x=";
    std::cin>>x;
    std::cout<<"n=";
    std::cin>>n;
    multiples(x, n);
    std::cout<<"\nxFloat=";
    std::cin>>xFloat;
    multiples(xFloat, n);
    std::cout<<"\nxDouble=";
    std::cin>>xDouble;
    multiples(xDouble, n);
}
THANKS @troaat very much
u must be genius with codings haha it was a fast reply.
Topic archived. No new replies allowed.