Metro supermarket is a new supermarket opening in Riyadh. It offers attractive discounts for its customers.
Write a program that will display to the user his new total price after discount. The program should read the total price from the user, calculate and display the new total price based on the following
• If the total price is greater than or equals to 3000, the discount percentage is 30%
• If the total price is greater than or equals to 1000 and less than 3000, the discount percentage is 20%
• If the total price is greater than or equals to 500 and less than 1000, the discount percentage is 10%
• If total price is less than 500, display that there is no discount
Please follow exactly the sample outputs.
Notice: Use while and do while and for loops to implement this program(write program 3 times using different loops). The program exits when the user enter 0 to quit.


Thx for ur time (",)

If you mean "will you write it for me", the answer is no. If that's not what you mean then please explain in more detail why you can not write the assignment.

lool!! no it's not.. i'm doing it right now..
but i'm facing some difficulties as i'm new to programming..
i'm doing it using do while.. but don't know how to do using for.. i've learned that if i wanna use for loop, i should have a range.. i dunnu where is the range here..

i'll post my solution in fe minutes if ur interested in helping me..

thx

hey guys..
i dunnu why the loop is not running.. it stops with the cin :W

this is my work.. would some chick where is my mistakes plz?!

#include <iostream>
using namespace std;

int main ()
{
	double tol_price, new_tol;
	int count=0;
	do {
	
		cout<<"*************Welcome to \"Metro supermarket\"*************"<<endl
			<<"__________________________________________________________\n"
			<<"\"Metro\" supermarket offers:\n"
			<<" ---------------------------------------------------- \n"
			<<"| 10 % discount for a total price of  500 -  999$        |\n"
			<<"| 20 % discount for a total price of 1000 - 2999$        |\n"
			<<"| 30 % discount for a total price of 3000$ & above       |\n"
			<<" ---------------------------------------------------- \n"
			<<"Dear customer please enter your sales’ total price:		\n";

		cin>>tol_price;

		if (tol_price <500)
		cout<<"Sorry dear customer you can't have a discount.\n"
			<<"Please pay your sales' total price= "<<tol_price<<"$ to the cashier.\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>500 && tol_price<=999)
		cout<<"Dear user you are going to get a 10% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 50 = "<<new_tol<<"$\n"

			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>=1000 && tol_price<=2999)
		cout<<"Dear user you are going to get a 20% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 300 = "<<new_tol<<"$\n"

			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>=3000)
		cout<<"Dear user you are going to get a 30% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<<" - 900 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

	
		count++;
		}while (count=0);

return 0;
}

OPS!! ok i found the reason why the loop wasn't running...
but now i've a different issue..
whenever i start without debugging, i get a window that says: Debug error! and that the variable new_tol is being used without being initialized..

i didn't understand that

You should post your code in code tags. This way it will be easier to read it. If you look closely in the edit box you will see some help in the edit box that's in light-grey text.

// put your code here

And post entire program so people can help you

commented: Well said +30

while (count=0); has to be while (count==0); If you write while (count=0); then variable count gets assigned value 0, so this means the assignment will return zero which is equal to false with the result the while loop won't run :) ...

This is my last solution... i'm still getting the window that says Debug error! and that the variable new_tol is being used without being initialized..

AND.. i want the program to exit when i press 0.. but it didn't work.. dunnu why :S

#include <iostream>
using namespace std;

int main ()
{
	double tol_price, new_tol;
	int count=0;
	char ch;
	do{
	do {
	
		cout<<"*************Welcome to \"Metro supermarket\"*************"<<endl
			<<"__________________________________________________________\n"
			<<"\"Metro\" supermarket offers:\n"
			<<" ---------------------------------------------------- \n"
			<<"| 10 % discount for a total price of  500 -  999$        |\n"
			<<"| 20 % discount for a total price of 1000 - 2999$        |\n"
			<<"| 30 % discount for a total price of 3000$ & above       |\n"
			<<" ---------------------------------------------------- \n"
			<<"Dear customer please enter your sales’ total price:		\n";

		cin>>tol_price;

		if (tol_price <500)
		cout<<"Sorry dear customer you can't have a discount.\n"
			<<"Please pay your sales' total price= "<<tol_price<<"$ to the cashier.\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>500 && tol_price<=999)
		cout<<"Dear user you are going to get a 10% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 50 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>=1000 && tol_price<=2999)
		cout<<"Dear user you are going to get a 20% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 300 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";

		if (tol_price>=3000)
		{cout<<"Dear user you are going to get a 30% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<<" - 900 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";
		}

		cout<<"Press 0 to exit the program"<<endl;
	
		count++;
		}while (tol_price>0);
		}while (ch==0);
return 0;
}

I get these two compiler warnings that you need to fix before attempting to run the program

1>c:\dvlp\test1\test1\test1.cpp(36) : warning C4700: uninitialized local variable 'new_tol' used
1>c:\dvlp\test1\test1\test1.cpp(53) : warning C4700: uninitialized local variable 'ch' used

Always treat warnings are errors because in most cases they are.


>> }while (ch==0);
change that to ch!=0

yeah i got those warnings.. and they are the ones which keeps getting me that window that they are being used without being initielized...

so what am i supposed to do abt them.. i dunnu how to remove and fix them.. :(

I gather that you did not write the code you posted. You are getting a warning on the line while (ch==0); because the variable ch was never initialized to anything, it just contains whatever random junk (data) happens to be in the memory location when main() is entered. How do you fix it? initialize the variable to something (usually 0) char ch = 0;

ok the char i can equal it to 0.. as it's just to quit the program.. even though that didn't work on the program dunnu why !!..
but the new tol.. how am i gonna fix it.. it's supposed to be calculated by the program.. am not supposed to equal it to anything.. right??

but the new tol.. how am i gonna fix it.. it's supposed to be calculated by the program.. am not supposed to equal it to anything.. right??

Yes you do need to set it to something. Look at the logic of your program -- all it does is display text on the screen for each of those if statements. You need to add something to each if statement to set the value of new_total. And don't forget to add { and } around those if statements

if( ... )
{
   cout << // blabla;
   new_total = ???
}

OH.. ok i realised that i forgot the original equation..
i did it..
but only one thing is missing .. how do i exit the program when i press 0.. the char ch=0 didn't work..

this is the last code now..

#include <iostream>
using namespace std;

int main ()
{
	double tol_price, new_tol;
	int count=0;
	char ch=0;
	do{
	do {
	
		cout<<"*************Welcome to \"Metro supermarket\"*************"<<endl
			<<"__________________________________________________________\n"
			<<"\"Metro\" supermarket offers:\n"
			<<" ---------------------------------------------------- \n"
			<<"| 10 % discount for a total price of  500 -  999$        |\n"
			<<"| 20 % discount for a total price of 1000 - 2999$        |\n"
			<<"| 30 % discount for a total price of 3000$ & above       |\n"
			<<" ---------------------------------------------------- \n"
			<<"Dear customer please enter your sales’ total price:		\n";

		cin>>tol_price;

		if (tol_price <500)
		cout<<"Sorry dear customer you can't have a discount.\n"
			<<"Please pay your sales' total price= "<<tol_price<<"$ to the cashier.\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";


		new_tol=tol_price-50;
		if (tol_price>500 && tol_price<=999)
		cout<<"Dear user you are going to get a 10% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 50 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";


		new_tol=tol_price-300;
		if (tol_price>=1000 && tol_price<=2999)
		cout<<"Dear user you are going to get a 20% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<< " - 300 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";


		new_tol=tol_price-900;
		if (tol_price>=3000)
		{cout<<"Dear user you are going to get a 30% discount.\n"
			<<"Your new total price after the discount is= "<<tol_price<<" - 900 = "<<new_tol<<"$\n"
			<<"Thank you very much for visiting \"Metro\" supermarket.\n";
		}

		cout<<"Press 0 to exit the program"<<endl;
	
		count++;
		}while (tol_price>0);

		}while (ch!=0);
return 0;
}

You need to re-read my previous post -- pay attention to details this time.

Yes you do need to set it to something. Look at the logic of your program -- all it does is display text on the screen for each of those if statements. You need to add something to each if statement to set the value of new_total. And don't forget to add { and } around those if statements

if( ... )
{
   cout << // blabla;
   new_total = ???
}

i'm not sure i understood this..
but u said that i need to add smthn to the if statement.. i did.. which is the equation >> new_tol=tol_price-900;
but i didn't get the part>>>don't forget to add { and } around those if statements

ANYWAY.. the program works fine now.. but the problem is that it doesnt exit when i press 0 :S

When there are more than one line that belongs to an if statement they need to be enclosed in { and } braces

if ( condition is true )
{
    statement 1
    statement 2
    ...
}

Otherwise, without the { and }, only the statement immediately following the if condition is executed. All other statements are executed regardless of the if condition.

if( condition is true )
    statement 1
statement 2  // this line is executed regardless of whether
                   // the if condition is true or false

In your program new_tol=tol_price-900; is executed regardless of the value of tol_price

ok got it..
but what about the exit thingy ??

OMG !! i still have to do it using while and for...
i can manage the while.. but the for is hard !! UGH..

i think i'll just hand it like this am not good at this... i spend all this time on do-while..


thnx man for help.. i really appreciate that..
xoxo

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.