This program will calculate commision based on the value of sales made...

im getting three errors so far...

1>h:\cs110\assignment6\assignment6.cpp(22) : warning C4700: uninitialized local variable 'third' used
1>h:\cs110\assignment6\assignment6.cpp(22) : warning C4700: uninitialized local variable 'second' used
1>h:\cs110\assignment6\assignment6.cpp(22) : warning C4700: uninitialized local variable 'first' used.

I was reading some books and some webpages but could find a place to find the "easy" error as they called it :(

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void salesValue(double dollars);
void commission (double dollars,double first,double second,double third);
void calculate (double dollars,double first,double second,double third);
//function prototypes

int main ()
{
	double dollars;
	double first;
	double second;
	double third;

	cout<<"What is the sale value?"<<endl;
		cin>>dollars;

commission (dollars, first, second,  third);
salesValue (dollars);
calculate (dollars, first, second, third);

	system("pause");
	return 0;

}

void salesValue (double dollars)
{
	cout<<"The sale value was"<<dollars<<endl;
	

}

void commission (double dollars,double first,double second,double third)
{
	first=(dollars*0.02);
    second=(dollars*0.03);
    third=(dollars*0.05);
}

void calculate (double dollars,double first,double second,double third)

{

	if (dollars < 1000)
		cout<<first<<"Comission was 2% "<<endl;
		
	  else if (dollars > 1000 && dollars <=10000)
				cout<<second<<"commission was 3%"<<endl;
				else if (dollars >=10001)
					cout<<third<<"commission was 5%"<<endl;
		     		else if  (dollars >= 50000)
						cout<<"This store does not allow sells over 50000"<<endl;
					else 
						cout<<"Wrong imput"<<endl; 
}

Recommended Answers

What's the difference?

void foo ( ) {
  int a; // uninitialised :(
}

vs.

void foo ( ) {
  int a = 0; // initialised :)
}

> warning C4700: uninitialized local variable 'third' used
So initialise them then!

Jump to Post

There is nothing in first second or third when you are calling your method. Where should these values come from? I think you mean to pass them by reference, so add a & before each variable name in your prototype and function definitions (but not where you call it)
For …

Jump to Post

All 6 Replies

What's the difference?

void foo ( ) {
  int a; // uninitialised :(
}

vs.

void foo ( ) {
  int a = 0; // initialised :)
}

> warning C4700: uninitialized local variable 'third' used
So initialise them then!

There is nothing in first second or third when you are calling your method. Where should these values come from? I think you mean to pass them by reference, so add a & before each variable name in your prototype and function definitions (but not where you call it)
For example: void commission (double dollars,double & first,double & second,double & third) and change line 8 to reflect this but leave line 22 as it is.
Your other method doesn't require this as you are not changing the values of those variables within the function.

EDIT: And Salem's advice ^^^^^^^^

ok so I initialized them :S
double dollars;
double first=0;
double second=0;
double third=0;

the program runs, no bugs at all but the teacher DID not teach us this yet :/ I think it was her fault for not telling us so I will ask her for sure :) thank you both tho... couldnt done it without you guys... sorry for being a selfish dude tho :D good night!

oh nevermind it does not work the way I intended it :S

DONE thank you guys!! heres the solution ;) :)

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void salesValue(double dollars);
void commission (double dollars,double & first,double & second,double & third);
void calculate (double dollars,double & first,double & second,double & third);
//function prototypes

int main ()
{
	double dollars;
	double first;
	double second;
	double third;

	cout<<"What is the sale value?";
		cin>>dollars;


salesValue (dollars);
commission (dollars, first, second, third );
calculate (dollars, first, second, third);

	system("pause");
	return 0;

}

void salesValue (double dollars)
{
	cout<<"The sale value was"<<dollars<<endl;
	

}

void commission (double dollars,double & first,double & second,double & third)
{
	first=(dollars*0.02);
    second=(dollars*0.03);
    third=(dollars*0.05);
}

void calculate (double dollars,double & first,double & second,double & third)

{

	if (dollars < 1000)
		cout<<"Comission was 2% "<<"and the calculation is"<<first<<endl;
		
	  else if (dollars > 1000 && dollars <=10000)
				cout<<second<<"commission was 3%"<<endl;
				else if (dollars >=10001)
					cout<<third<<"commission was 5%"<<endl;
		     		else if  (dollars >= 50000)
						cout<<"This store does not allow sells over 50000"<<endl;
					else 
						cout<<"Wrong imput"<<endl; 
}

sorry for the spamming...
multiple curly braces were applied in my last edit... else if statement were replaced by if () statements :) and now it really works.
{

}

Be a part of the DaniWeb community

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