I'm trying to figure out what the syntactical structure of this program should be. I think my equation at the top makes it clear what I am aiming to display to the user at the end of the program, but I'm not sure exactly how I should be going about doing this. Any help is appreciated. Thank you.
//calculator
#include <iostream>
#include <cctype>
usingnamespace std;
int main()
{
float rent, food, stuff, income, savings, time;
time = ( rent + food + stuff ) / income;
cout<<"Press enter to let me help you with your finances! :) \n\n";
cout<<"(Please enter only numeric values in dollars)\n\n";
cout<<"How much do you pay for rent plus utilities per month?\n\n";
cin>>rent;
cout<<"How much do you pay for food per month?\n\n";
cin>>food;
cout<<"How much do you pay for repairs + travel + entertainment?\n\n";
cin>>stuff;
cout<<"What's your total monthly income?\n\n";
cin>>income;
cout<<"How much in total do you have in savings?\n\n";
cin>>savings;
cout<<"You will go broke in approximately " << time;
cout<<" months. Good luck!";
rem = int time
if (rem < 12); {
cout<<"success";}
if (rem > 12); {
cout<<"failure";}
return 0;
}
You shouldn't think of line 11 as an equation. It is an instruction. It tells the computer to take the current values of the variables rent, food, stuff and income, do some arithmetic and store the result in the variable time.
Unfortunately, at that point in the program, none of those four variables have been assigned any particular value, so it doesn't do anything useful.
At line 24, you get the last of the required values supplied as input from the user. It is after that point that you should carry out the calculations.
sequence:
1 define variables
2 get data from user and store it in the variables
3 do the calculations
4 output the results.