N=P?

Original program
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>
#include <conio>
int main()
{
	int N, itemCnt=0;
   double price, totalPrice=0;
   cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
   cout<<"How many items? ";
   cin>>N;

   do
   {
   cout<<"Enter price of item: ";
   cin>>price;
   totalPrice+=price;
   itemCnt++;
   } while (itemCnt<N);

   cout<<"\n\nYou have "<< itemCnt <<" Items";         
   cout<<"\nThe Average Price Of The Item Is "<<totalPrice/itemCnt;
   cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
   cout<<"\n\nEnd Of Program";
   
getch();
return 0;
}



This is my edited version
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>
#include <conio>
int main()
{
	int N=0, P;
   double price, totalPrice=0;
   cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
   cout<<"How many items? ";
   cin>>N=P;

   do
   {
   cout<<"Enter price of item: ";
   cin>>price;
   totalPrice+=price;
   N--;
   } while (N/=0);

   cout<<"\n\nYou have "<< N <<" Items";         
   cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;
   cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
   cout<<"\n\nEnd Of Program";

getch();
return 0;
}


I tried to eliminated itemCnt from the original program, but then replace the cin>>N; to cin>>N=P; because don't want my N=0 at this line cout<<"\nThe Average Price Of The Item Is "<<totalPrice/itemCnt; after change become cout<<"\nThe Average Price Of The Item Is "<<totalPrice/N; where any number cannot be divided with 0, that why I change my code to this cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;

I think cin>>N=P; is wrong, is that possible to have something like N=P; to solve the problem above?

Somemore, is that correct to write not-equal in this way (N/=0)? Thanks...
Somemore, is that correct to write not-equal in this way (N/=0)?

No. That means N = N/0 which is very very bad.

If you want N and P to be the same, try this:

1
2
cin>>N;
P = N;


Inequality N != 0
or N not_eq 0
Thanks Moschops for the help, problem solve also with the help from ne555 >> N != 0 but cannot solve if using N not_eq 0, the error is
Do-while statement missing )
weird, because the operators are equivalent.
wait... you don't have namespaces ¿what compiler are you using?
i use Borland C++ to run and get error:
Do-while statement missing )

after that I tried using Visual Studio 2010 C++ and get error:
1>c:\users\128a5s5\documents\visual studio 2010\projects\10\10\10.cpp(20): error C2146: syntax error : missing ')' before identifier 'not_eq'
1>c:\users\128a5s5\documents\visual studio 2010\projects\10\10\10.cpp(20): error C2146: syntax error : missing ';' before identifier 'not_eq'
1>c:\users\128a5s5\documents\visual studio 2010\projects\10\10\10.cpp(20): error C2065: 'not_eq' : undeclared identifier
1>c:\users\128a5s5\documents\visual studio 2010\projects\10\10\10.cpp(20): error C2143: syntax error : missing ';' before 'constant'
1>c:\users\128a5s5\documents\visual studio 2010\projects\10\10\10.cpp(20): error C2059: syntax error : ')'
Show us the code and we'll tell you the error.
Here is the code that got error above~Thanks~

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>
#include <conio>
int main()
{
	int N=0, P;
   double price, totalPrice=0;
   cout<<"Program To Calculate The Average and Total Price Of N Items \n\n";
   cout<<"How many items? ";
   cin>>N;         
   P=N;

   do
   {
   cout<<"Enter price of item: ";
   cin>>price;
   totalPrice+=price;
   N--;
   } while (N not_eq 0);

   cout<<"\n\nYou have "<< P <<" Items";
   cout<<"\nThe Average Price Of The Item Is "<<totalPrice/P;
   cout<<"\nThe Total Price Of The Item Is "<<totalPrice;
   cout<<"\n\nEnd Of Program";

getch();
return 0;
}
Last edited on
so, it's probably declared in this library

#include <iso646.h>

am i right? i don't know about the library though... just saw it on msdn documentary...
Your compiler is so out of date that it doesn't know what not_eq is. That's the problem. You can get a modern compiler for free. Please do so.
Thanks chipp for the library, it do help in Ms Visual Studio C++ but not Borland C++, I think Borland C++ is really out of date...lolx...

Moschops, is that Ms Visual Studio 2010 C++ consider out of date? Coz if I don't put this library #include <iso646.h> , it won't work as well...I don't know about that, pls guide, thanks...
Thanks chipp for the library provided...it do help in Visual Studio 2010 C++ but not in Borland C++, I think Borland C++ is really out of date...

Moschops, is that Ms Visual Studio 2010 C++ consider out of date? Coz I only can use it without any error if have #include <iso646.h> inside...I not really know about this, pls guide, thanks~~
Topic archived. No new replies allowed.