some simple questions

Pages: 12
Just repeatedly ask for the amount he sold for until they input "0", at which case the program should assume that is the end of sales.
welcome Zhuge (726)

yes but i don't understand the steps

could you please tell me the steps then i can write algorathim

1- what should i do

2- ..... etc
please see this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> 
using namespace std; 
int main() 
{ 
int sum; 
int num1,num2; 
sum = 0; 
cout << "Enter two numbers: "; 
cin >> num1 >> num2; 
while(num2 >= num1){ 
cout << num1 << " "; 
sum = num1 + num1; 
num1++; 
} 
cout<<"Sum = " << sum; 
        return 0; 
}


i;m trying to output the numbers between the two input numbers and then find their sum

this is an example

num1 = 2
num2 = 6

output = 2 3 4 5 6, sum = 120

my code is working but i cant find the correct sum

please help

waiting for you
Firstly, 2 + 3 + 4 + 5 + 6 == 20!

Secondly, you're resetting the value of sum on every loop iteration. You should do this instead:

sum += num1;
Last edited on
thanks it's working now

so can you help me witgh Q1??
thanks it's working now

can you help me with Q1? could write to me the code buecause i dont know how to write for it
where are you guys
Did you ask your teacher what does "solve this formula" mean? What did he tell you?
welcome

he didn't reply :(
hello again

please see this code

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
#include<iostream> 
using namespace std; 
int main() 
{ 
float s=0,p; 
int i,j,x; 
 
cout<<"x="; 
cin>>x; 
x++; 
 
for(j=1;j<=6;j++) 
{ 
p=1; 
for(i=1;i<=j;i++) 
p*=x; 
 
if(j%2==0) 
s+=(-p/j); 
else 
s+=(p/j); 
} 
cout<<"ln("<<x<<")="<<s<<endl; 
system("pause"); 
return 0; 
}


and this is the equation http://img571.imageshack.us/img571/3935/70196195.jpg

so is this the correct code for the euation??

i want just to make sure

No.
so how :(
Remove this -> x++;

Also turn this -> cout<<"ln("<<x<<")="<<s<<endl; into -> cout<<"ln("<<x+1<<")="<<s<<endl;

Oh, and x should be a float.
Last edited on
hello m4ster

this is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream> 
using namespace std; 
int main() 
{ 
float s=0,p; 
int i,j;
float x; 
cout<<"x="; 
cin>>x; 
for(j=1;j<=6;j++) 
{ 
p=1; 
for(i=1;i<=j;i++) 
p*=x; 
 
if(j%2==0) 
s+=(-p/j); 
else 
s+=(p/j); 
} 
cout<<"ln("<<x+1<<")="<<s<<endl; 
system("pause"); 
return 0; 
}


so this one is correct now, am i right?

you know my problem is in math, i'm really poor in math :(
and i want to edit this code to accept one number and then show the numbaer whether is a prime or not

this is the code and i try to edit but i couldn't

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int num,isprime;
cout <<"Please enter a number: ";
cin >> num;
for(int i=2; i<=num;i++)
{
isprime = 1;
for(int j=2; j<=i ; j++)
{
if( i == j)
continue;
else if( i % j == 0){
isprime = 0;
}
}
if(isprime == i){
cout<<i<<"is a prime number ";
}else{
cout<<i<<"is not a prime number ";
}
}
please help me!
Regarding this: http://img571.imageshack.us/img571/3935/70196195.jpg

Why don't you write a function to evaluate one of the terms of the series?

1
2
3
4
double calc_term(double x, int n)
{
    // calculate xn/n here
}


Then call that function in a loop, alternatively adding or subtracting each term from n = 1 to n = 6?
Topic archived. No new replies allowed.
Pages: 12