Static Variable problem
Nov 16, 2014 at 4:57pm UTC
I have this assignment for school. Here's what I have so far. Can anyone tell me if I'm on the right track?
http://gyazo.com/251f5f144c3d54ade87635dded706ccd
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
int pb(){
static double unit = 2;
}
int main(){
double x,y;
do {
cout << "Enter a size and price" <<endl;
cin>>x,y;
if ( x/y < pb() ) {
cout<< x/y <<endl;
}
} while (x != 0 || y !=0);
return 0;
}
Nov 17, 2014 at 11:16am UTC
What is the program supposed to do?
Nov 17, 2014 at 3:25pm UTC
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
#include <iostream>
using namespace std;
double pb(double arg)
{
static double unit = 999999999;
if (arg<unit && arg!=0)
{
unit = arg;
}
return unit;
}
int main(){
double ounce, price;
while (true )
{
cout << "Enter a size and price" <<endl;
cin >> ounce >> price;
if (ounce==0 || price==0) break ;
double m = price/ounce;
cout << "\n lowest price: " << pb(m) << "\n\n" ;
}
return 0;
}
Topic archived. No new replies allowed.