LOL I made a very stupid mistake there. Thank you guys again for helping me. I will let you know how the program turns out.
-Nick
Printable View
LOL I made a very stupid mistake there. Thank you guys again for helping me. I will let you know how the program turns out.
-Nick
Ok I know what you could do within your math, dont need to use if I belive. You want to make it so for ever orange you buy it makes the total lower right? Why not do this?
1st you need to make 4 ints: int a, int b, int c, and int d.
2nd make int a apples, int b oranges, and int c and d nothing atm.
3rd you want to know how meny oranges would take off on apples no? Then take int b - int a that would = how meny apples they will have to buy. This will be int c, make that look like this4th now take int c times lets say 1.50 (this is how much the apples cost alone)Code:c = b-a;
5th now we will do the same to bCode:c = c*1.50;
7th now add thes togather.Code:b = b*1.50;
8th just show what d = to and thats your totall prise. I didnt even need to use the if half. Hope that helps you.Code:d = b+c;
I am having another probelem now lol. When the program prints the total it prints it like this 140 and I need it to print like this 14.00. It might be the variable types but I have changed them from int to double to float and there has been no change.
Thanks for reading.
-Nick
WAIT! forget everything I saidXD Will ok not everything. Ok in my code I found a little a problem... ok thos ints I told you to make, trun them into float like so...Also change step 3 code toCode:float a;
Heres what ints, long, bla bla can do with numbers.Code:c = a-b;
int: used to store integers (whole numbers, no decimals/fractions)
long: used to store larger integers
double: used to store numbers with two decimal places
float: used to store numbers with multiple decimal places
char: used to store a single character
This is why you need to learn math kids:) So you dont have to use the "if" LOL. Best of luck on your work. (I am a kid, I was just playing)
I changed the variables that would use float to float but nothing happened, So then I changed them all to float and its still not working. This is very strange. LOL I am basically done with the program with one more little hurdle to jump and its the worst one. Do you guys see anything causing this that I don't see in this code?
Code:#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
float orange (int firsta);//orange prototype.
float apple (int firstb);//apple prototype.
int main()
{
//vars
string username; //Users name.
int usra,usro; //Users choice of apples. Users choice of Oranges.
float applecal, orangecal; //Apple calculations. Orange calculations.
float addao; //adding apples and oranges together.
float result, resultd; //The final result. The result of the discount.
//vars end
//sig
cout<<"*********************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* Nicks Grocery store *"<<endl;
cout<<"* *"<<endl;
cout<<"*********************************************************"<<endl;
cout<<endl;
//sig end
//Program
cout<<"Welcome to Nick's Grocery Store."<<endl;
cout<<endl;
cout<<"****Todays Specials.*****"<<endl;
cout<<"*Buy one Apple get one *"<<endl;
cout<<"*free! *"<<endl;
cout<<"*-----------------------*"<<endl;
cout<<"*Each Orange you buy *"<<endl;
cout<<"*deducts 1% off your *"<<endl;
cout<<"*bill. *"<<endl;
cout<<"*************************"<<endl;
cout<<"Max of 100 items per customer"<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<endl;
//Asks for Users name.
cout<<"Enter your name :";
cin>>username;
cout<<endl;
//Asks how many Apples the User wants.
cout<<"How many Apples would you like "<<username<<" :";
cin>>usra;
cout<<endl;
//Asks how many Oranges the User wants.
cout<<"How many Oranges would you like "<<username<<" :";
cin>>usro;
cout<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
applecal= apple(usra);//Calling the apple function/
orangecal= orange(usro);//Calling the orange function.
addao= applecal+orangecal;//Adding applecal and orangecal together.
resultd= 100/usro*addao;//Finds the amount of money you have saved.
result= resultd-=addao;//Deducts the amount you have saved from the total.
cout<<endl;
cout<<"Your total is :"<<result<<endl;
getch();
return 0;
//Program end
}
//Math for Apples
float apple(int firsta)
{
return firsta/2+firsta%2;
}
//Math for Oranges
float orange(int firstb)
{
return firstb*1.50;
}
addao= applecal+orangecal;//Adding applecal and orangecal together.
cout << addao << endl;
resultd= 100/usro*addao;//Finds the amount of money you have saved.
cout << resultd << endl;
result= resultd-=addao;//Deducts the amount you have saved from the total.
cout << result << " " << resultd << " " << addao << end;
Figure it out, do some debugging.
The last expression looks very odd indeed.
Here is how I showed it, its just a sample, hope it helps.
Code:#include <iostream>
using namespace std;
float a;
float b;
float c;
float d;
int main(){
cout << "Enter a number: ";
cin >> a;
cout << "Enter a second number: ";
cin >> b;
c = a-b;
c = c*1.50;
b = b*1.50;
d = c+b;
cout << "The sum is: " << d;
system("pause");
}
Can anyone help me with getting this program to display the total price correctly. It is displaying like this 144 but I want to to display this 14.40.
Thanks for reading.
-Nick
Code:#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
//prototypes
float applecal(int);//Applecal function.
float orangecal(int);//Orangecal function.
//
int main()
{
//text and background color
system("color 8F");
//text and background color end
////////////////////////////////////////////////////////////////////////////////
//vars
int usro , usra; //The users choice of apples and oranges.
float usrac , usroc; //The calculated results of the users input.
float add , result; //Adding both usrac and usroc together. Main result.
//vars end
////////////////////////////////////////////////////////////////////////////////
//sig
cout<<" -*********************************************************-"<<endl;
cout<<" ** **"<<endl;
cout<<" **** Nicks store ****"<<endl;
cout<<" ** **"<<endl;
cout<<" -*********************************************************-"<<endl;
cout<<endl;
//sig end
////////////////////////////////////////////////////////////////////////////////
//Program
cout<<"Welcome to Nick's Store."<<endl;
cout<<endl;
cout<<"****Todays Specials.*****"<<endl;
cout<<"*Buy one Apple get one *"<<endl;
cout<<"*free! *"<<endl;
cout<<"*-----------------------*"<<endl;
cout<<"*Each Orange you buy *"<<endl;
cout<<"*deducts 1% off your *"<<endl;
cout<<"*bill. *"<<endl;
cout<<"*************************"<<endl;
cout<<"Max of 100 items per customer"<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<endl;
//Asks how many Apples the User wants.
cout<<"How many Apples would you like :";
cin>>usra;
cout<<endl;
applecal(usra);//calling applecal function.
usrac=applecal(usra);//getting USRA variable data from applecal.
//Asks how many Oranges the User wants.
cout<<"How many Oranges would you like :";
cin>>usro;
cout<<endl;
orangecal(usro);//calling orangecal function.
usroc=orangecal(usro);//getting USRO variable data from orangecal.
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<endl;
add = usrac + usroc;//Adds usrac and usroc together.
result = (100/usro*add)- add;
cout<<"Your total is :"<<result<<endl;
//end program
getch();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//applecal function.
float applecal(int first)
{
return first/2*1.00+first%2;
}
////////////////////////////////////////////////////////////////////////////////
//orangecal function.
float orangecal(int first)
{
return first*1.50;
}
////////////////////////////////////////////////////////////////////////////////
ternary operator to the rescue.
Maybe not in the spirit of the assignment, but who cares :)Code:delivered=(type==APPLE?number*2:number);
Why do schools like assigning such asinine programming homework?
lol thanks for the reply but I cant use anything I havent learnt yet. my teacher told me to try deviding the end resuly by 100.00, I get the correct answer and the decemals are in the right place when I do it but it still isnt displaying that extra 0 there. I think it is doing it because the 0s would just keep going and going and going if it had to display them. Is there a way I can get it to just display the last zero like this 14.40 instead of this 14.4.Quote:
Originally Posted by jwenting
Thanks for reading and sorry about spelling mistakes.
-Nick
can you use setprecision
I just gave it a try but it still isnt showing that extra 0. :confused: I am clueless. Anyone else know whats going on with my program?Quote:
Originally Posted by Syneris
-Thanks for reading.
-Nick
No offence, but you should really try figuring some of this out yourself ... so far as I can tell, besides the main body of your program, everything was done for you .... try searching through the internet. I recommend google!Quote:
Originally Posted by Nick_365
No offence taken, I guess im kinda bending that rule about people doing your homework for you lol. I will google it and try my best to figure this out. Lol and if that fails then I guess I will be back here to bug you guys some more :p .
-Nick