Tell me whats wrong in my code please

Write your question here.
Write a program that display running total of sales as many as enter by the user. It also displays text amount of 30% of total sale 30% off stock cost and then it display remaining amount of profit.
<>
#include <iostream>
using namespace std;
int main()
{
//s=sales, sc=off stock cost, ta=text amount , p=profit
int s, ta, sc, p=0;

cout << "\nEnter sales:";
cin >> s;
ta = s - 0.3;
cout << "\n Text amount is:" << ta;
sc = s - 0.3;
cout << "\n Stock Cost is:" << sc;
p = s - (ta - sc);
cout << "\n Profit is:" << p;
system("pause");
return 0;

}
<>
What is the observed issue?
* Fails to compile?
* Crash on run?
* Unexpected output?


1. How do you compute 30% of something like 's'?

2. int is integer; no fraction.
Thank you for the reply
My problem is Unexpected output..
unexpected Output is
Enter sales:500
Text amount is:499
Stock Cost is:499
Profit is: 500 // how after deduction of Text amount and Stock cost profit is always same as sales..
above mention Output isn't according to my Question"Write a program that display running total of sales as many as enter by the user. It also displays text amount of 30% of total sale 30% off stock cost and then it display remaining amount of profit."

my English is bad hope you understand
And if int is integer; no fraction then what should be use instead of int?
Last edited on
User gives '500' for s.

s - 0.3 is thus 500 - 0.3, which is 499.7.
You do store the 499.7 into 'ta', which is an int. Therefore, ta == 499.

s - (ta - sc) with those values means 500 - (499 - 499).
The (499 - 499) equal 0. Therefore p = 500 - 0, p == 500.

A floating point type is double.


The int vs double is not your real issue.

The real issue is that your math is weak.


How much is 30% of 500?
Thanks
I know 30% of 500 is 150
but
how can we write the formula of ta and ca?
like ta=s-30%; // but it gives us error
now just want to know that how can we write the formula of ta or sc ?
hope you understand my problem ?

OR
is my above code 100% correct ?
Last edited on
I know 30% of 500 is 150

That is correct, but how do you know that? How do you calculate it (in your mind)?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#include <iostream>

using namespace std;

double s;
double ta;

int main ()
{

cout << "please enter sale ammount" << endl;
cin >> s;
ta = (s * 0.3);

}


you'll want to add in a loop and a couple of if statements to check that the value entered into s is numeric, otherwise your program will crash if the value for s is a letter or word (this is the issue i was having).
Last edited on
500*0.3=150.
OMG now i understand what is my mistake me need to do multiply not subtraction..
Thank you for the Help (Fojaxx and keskiverto) Sir. :-))
Last edited on
Suppose you give a dinner party for six guests, but your table seats only four. In how many ways can four of the six guests arrange themselves at the table? Any of the six guests can sit in the first chair. Any of the remaining five can sit in the second chair. Any of the remaining four can sit in the third chair, and any of the remaining three can sit in the fourth chair. (The last two will have to stand.) So the number of possible arrangements of six guests in four chairs is 6*5*4*3, which is 360. Write a program that calculates the number of possible arrangements for any number of
guests and any number of chairs. (Assume there will never be fewer guests than chair)

soution????
Last edited on
Topic archived. No new replies allowed.