check

Hey guys..so my prof gave me this question but am confused. So check this out....Write a program that ask a user to enter three values then the program should add 7 to the first value,multiply the second value by 3 and subtract 9 from the last value using a function. The program should call the function in the main program and display the new values.
Show us you care enough to try first. We can help you from there.
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

#include<iostream.h>

int add(int a,int x=7){
  return a+x;
  }
int product(int b,int y=3){
  return b*y;
  }
int subtraction(int c,int z=9){
  return c-z;
  }

int main()
{
int a,b,c;

cout<<"Enter first,second and third value value:\n";
cin>>a,b,c;

cout<<add (a,x)n;
cout<<product (b,y) \n;
cout<<subtraction (c,z) \n;


 return 0;
}
Last edited on
You're almost fine except for calling your functions and your use of cin and cout.


1
2
3
4
5
cin >> a >> b >> c;  // Use successive operators, not comma

cout<<add (a) << '\n';    // Again use successive operators and quote the newline
cout<<product (b) << '\n';
cout<<subtraction (c) << '\n';


Note that x, y and z are not defined when you call your functions. Because you define default values for the second argument of each of your functions, it is not necessary to supply the second argument.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

so i have to define the x, y and z like that

1
2
3
4
 int main<>
 {

 int a,b,c,x,y,z
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
#include <iostream>
using namespace std;
int add(int a,int x){
	cout<<a+x;
return a+x;
}
int product(int b,int y){
	cout<<b*y;
return b*y;
}
int subtraction(int c,int z){
	cout<<c-z;
return c-z;
}

int main()
{
int a,b,c;

cout<<"Enter first,second and third value value:\n";
cin>>a>>b>>c;
add(a,7);
cout<<endl;
product(b,3);
cout<<endl;
subtraction(c,9);
return 0;
}
closed account (48T7M4Gy)
so i have to define the x, y and z like that


1
2
3
 int main<>
 {
    int a,b,c,x,y,z


Yep, then you can use cin >> a etc to get input.
Last edited on
ok thank you all
Topic archived. No new replies allowed.