Hi, first time attempting this. I have been web programming with old school HTML for a number of years as a hobby - and have exhausted its limitations a long time ago. Currently I have spent about... 3 days trying to learn some C++ - this is what I got down so far (very limited - be gentle).
The program below is not meant to be of any use - just review of what I've learned. What I wanted it to do is basically loop the function that asks "please report a small number" (if the answer is no/FALSE - I want to continue to loop until the answer is TRUE) - however I am to understand that the compiler and the program read code from top to bottom - how do you get it to go back up to read a var/fucntion that has changed?
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int numb001;
string myname;
cout<<"Hi, I will be summarizing my skills to date; this program \nwas written by Nacent_Grammer.";
cout<<"\n---------------------------------------------------------";
cout<<"\n\nPlease enter your name first: ";
cin>> myname;
cin.ignore();
cout<<"\nHello " << myname <<". Glad you could join me today! Let us begin \n";
cout<<"\nFirst " <<myname <<", please report a small number to me: \n\nNumber: ";
cin>> numb001;
cin.ignore();
cout<<"\nThe number you entered was: '" << numb001 <<"'. Is this correct?\n\n 1 = Yes | 2 = No";
int confirm001; // Confirmation of either 1 = Yes or 2 = No!
cout<<"\n\nSelection: ";
cin>> confirm001; // First confirmation.
cin.ignore();
if ( confirm001 == 1 ) { // if YES
cout<<"\nOk, time to move on...";
system ("PAUSE");
}
else if ( confirm001 == 2 ) { // if NO
cout<<"\nOK, what is it then: ";
cin>> numb001;
cin.ignore();
cout<<"\n\nIs this correct now?";
cout<<"\n\nSelection: ";
confirm001 != 1 , 2;
cin>> confirm001;
}
cin.get();
/* The beginning of the variable list - includes menu selections and variables to be computed*/
float sum01;
float nsum; // end of sum
float mult01;
float nmult; // end of multiplication
float divide01;
float ndivide; // end of divide
float subtract01;
float nsubtract; // end of substraction
// End of Menu/Variable options
int selection001; // menu selection variable!
cout<<"\n\n---------------------------------------------------------";
cout<<"\n\nOk, now to move on. You said your number was '" <<numb001 <<"'. \nI would like to do some math for you!";
cout<<"\n\n Please, select from the following: \n\n (1) Add another number to your old number \n (2) Multiply your old number with a new number \n (3) Divide some numbers!\n (4) Or, subtract some numbers!\n\n";
cout<<"\n\nSelection: ";
// Beginning of IF statements for menu selection!
cin>> selection001;
if ( selection001 == 1 ) {
cout<<"\n\nWhich number do you wish to add then? \n\nNew number: ";
cin>> nsum;
cin.ignore();
sum01 = numb001 + nsum;
cout<<"\n\nWhen you add '" << numb001 <<"' and '" << nsum <<"' you get '" << sum01 <<"'\n\nThank you, I must close the program now!";
}
else if ( selection001 == 2 ) {
cout<<"\n\nWhich mumber do you wish to multiple then? \n\nNew number: ";
cin>> nmult;
cin.ignore();
mult01 = numb001 * nmult;
cout<<"\n\nWhen you multiply '" << numb001 << "' and '" << nmult <<"' you get '" << mult01 <<"'\n\nThank you, I must close the program now!";
}
else if ( selection001 == 3 ) {
cout<<"\n\nWhich number do you wish to divide then? \n\nNew number: ";
cin>> ndivide;
cin.ignore();
divide01 = numb001 / ndivide;
cout<<"\n\nWhen you divide '" << ndivide <<"' into '" << numb001 <<"' you get '" << divide01 <<"'\n\nThank you, I must close the program now!";
}
else if ( selection001 == 4 ) {
cout<<"\n\nWhich new number do you wish to subtract from your old number, '" << numb001 <<"'?\n\nNew number: ";
cin>> nsubtract;
cin.ignore();
subtract01 = numb001 - nsubtract;
cout<<"\n\nWhen you subtract '" << nsubtract <<"' from '" << numb001 <<"' you get '" << subtract01 <<"'\n\nThank you, I must close the program now!";
}
// End of IF statements!
cin.get();
}
I have been going through the tutorials and I have been trying to read other postings (even got myself a little manual about 500 pages long), but I think I am asking a question a little a head of myself.
-J