please help me how to write this program.


write a program to calculate:

a - b / c * d + e *f % g

where a , b , c , d , e , f , g are integer


the output format like.
a=
b=
c=
d=
e=
f=
g=

Recommended Answers

All 7 Replies

Show us what have you done till now

im just a beginner but this may work:

#include <iostream>
/*you may need more #includes i don't know*/
/*define all your integers hear (and a one called calculate)*/

int main(){
     cout << "watever";
     cin >> a;
     cin >> b;
     etc.
     cout << calculate();
}
int calculate(){
     return a - b / c * d + e *f % g
}

i think this will have a bunch of syntax errors but i haven't used this in a while.

hope it helped

#include <iostream>
/*you may need more #includes i don't know*/
/*define all your integers hear (and a one called calculate)*/

int main(){
     cout << "watever";
     cin >> a;
     cin >> b;
     etc.
     cout << calculate();
}
int calculate(){
     return a - b / c * d + e *f % g
}

it should be return (a-b/c...
and mabye it should be calculate(a,b,c,d,e,f,g)

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f,g,h;

cout<<"\n Enter a";
cin>>a;
cout<<"\n Enter b";
cin>>b;
cout<<"\n Enter c";
cin>>c;
cout<<"\n Enter d";
cin>>d;
cout<<"\n Enter e";
cin>>e;
cout<<"\n Enter f";
cin>>f;
cout<<"\n Enter g";
cin>>g;
cout<<"\n Enter h";
cin>>h;
int y;

y=a-b/c*d+e*f%g;
cout<<"\na-b/c*d+e*f%g"<<endl;
cout << "y="<<y<<"\n";
cout<<endl;
return 0;
}


how to make this program to run,,,,,3 times when run the program.....

Next time use code tags...they increases readability

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f,g,h;

cout<<"\n Enter a";
cin>>a;
cout<<"\n Enter b";
cin>>b;
cout<<"\n Enter c";
cin>>c;
cout<<"\n Enter d";
cin>>d;
cout<<"\n Enter e";
cin>>e;
cout<<"\n Enter f";
cin>>f;
cout<<"\n Enter g";
cin>>g;
cout<<"\n Enter h";
cin>>h;
int y;

y=a-b/c*d+e*f%g;
cout<<"\na-b/c*d+e*f%g"<<endl;
cout << "y="<<y<<"\n";
cout<<endl;
return 0;
}
how to make this program to run,,,,,3 times when run the program.....

Embed it inside any loop(for,while etc...)
example

int count=0;
for(count=0;count<3;count++)
{
//code to be repeated
}
#include <iostream>
using namespace std;

int main()
{
    int a, b, c, d, e, f, g;

    for (int i=0; i<3; i++)
    {
        cout << "Please enter the interger to calculate:" << endl;

            cout << "a=";
            cin >> a;

            cout << "b=";
            cin >> b;

            cout << "c=";
            cin >> c;

            cout << "d=";
            cin >> d;

            cout << "e=";
            cin >> e;

            cout << "f=";
            cin >> f;

            cout << "g=";
            cin >> g;

            int y;
            cout << "y= a-b/c*d+e*f%g" << endl;
            y= a-b/c*d+e*f%g;

            cout << "y= " << y <<"\n";
            cout <<endl;
    }

    return 0;
}

is there any other way to do this program......

Well, you might want to put in some parenthesis to be more specific about your intentions. Otherwise, unless you are very certain of operator precedence rules, you can easily end up with a miscalculation because of an operation being done out of sequence when you have such a complicated equation. However, adding parenthesis can make the entire process even more visually complicated. So, since computers do things very quickly, you could explicitly do the temporary sums, products, etc. as separate calculations involving just two explicit operands to be absolutely, positively sure you are getting things done in the sequence you want. But that may or may not be worth your while.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.