Hi im programming a program thats going to count how how many doussins,grosses and pieces. there are if you enter a number. (just so u know ive started programming 1 week ago and havent programed alot cause school started) ok heres my problem: when i enter 502 pieces it says it 3grosses 3doussins and 10 pieces it should be 3,5,10 so doussins is wrong, if u look where it says antdussin=totantstycken/144; so maybe this problem is cause im not so good with math but i think 1 gross is 144 pieces and a doussin is 12 pieaces right?

# include <iostream>
# include <iomanip>
using namespace std;
int main()
{
 int totantstycken, antgross, antdussin,antstycken;
 cout<<"Ange antal:";
 cin>>totantstycken;
 antgross=totantstycken/144;
 antdussin=totantstycken/144;
 antstycken=totantstycken%12;
 cout<<totantstycken<<" sekunder bestar av "<<endl;
 cout<<"Gross"<<setw(5)<<antgross<<endl;
 cout<<"Dussin"<<setw(4)<<antdussin<<endl;
 cout<<"Stycken"<<setw(3)<<antstycken<<endl;
}
Member Avatar for kohkohkoh

then it must be your wrong statement of calculation which happened twice
antgross=totantstycken/144;
antdussin=totantstycken/144;

i think...

antgross=totantstycken/144;
antdussin=totantstycken/144;

u again divide the same value on the same divisor u must
replace the line :antdussin=totantstycken/144; with the following two lines :
totantstycken%=144; //get the nuber of non gross piesec
antdussin=totantstycken/12; //get the number of dussin

thank you stg110.

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.