TheZaw Valve mod
Reputation: 0
Joined: 01 Mar 2008 Posts: 1061 Location: Learning C++
|
Posted: Sat Apr 05, 2008 12:06 am Post subject: C++ "%" operan/operator |
|
|
Heya people! Im making a merchenting counculator (challenge from my brother) and i need a way to get remainders. He gave me a hint that the "%" operator divides and returns the remainder. I can't get it to work for me, as it returns false.
Heres my code btw, fully commented. Oh, and its not finished yet, as im stuck on this stage. Also, no goto deathbydinousour for me! (if you don't get that, go here: http://xkcd.com/292/)
#include <iostream>
using namespace std;
int goal, current, buy, sell;//declaring integers for use
int profitper, c, d, e, f; //integers used in the math part
int itemsper(int buy, int current);//function for returning items available with current cash
int main(){//main part of program
cout<<"Enter current money available for merchenting: ";
cin>>current;//gets current money for merchenting. Cout stands for console (keyboard) out. Cin stands for console in.
cin.ignore();//ignores enter, so cin.get doesn't trigger.
cout<<"Enter goal for total cash at end of merchenting: ";
cin>>goal;//Gets Goal for cash
cin.get();
cout<<"How much are you buying the item for: ";
cin>>buy;//gets how much to buy item for
cin.get();
cout<<"How much are you going to sell the item for: ";
cin>>sell;
cin.ignore();
itemsper(buy, current);
while (current<goal){//while current money is less than goal do this
profitper=sell-buy;//gets profit per item
}
cin.get();//when finished, press enter to terminate program
}
int itemsper(int buy, int current){
int temporary, temp2;//these integers will be thrown away later, just needed to store temporary values
temporary=current/buy;
temp2=current%buy;//the "%" operator returns the remainder of the divisor
if(temp2=0){
temporary=temporary-1;
}
cout<<temp2;
} _________________
|
|