What I meant about forward declaration was this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <windows.h>
#include <cmath>
#include <fstream>
using namespace std;
double x, y;
int i;
string z, s, t;
char d;
string l = ("wget.exe "), k = ("color ");
void ShowMenu();
void ProcessMenu();
void multiplication();
void file();
// all the other ones in a similar fashion
int main()
{
ShowMenu();
ProcessMenu(char MenuOption);
cin >> d;
}
void ShowMenu()
{
system("title OmniTool");
system("cls");
cout << ("Please choose a mode.") << endl;
cout << ("Press M to goto Multiplication") << endl;
cout << ("Press D to goto Division") << endl;
cout << ("Press A to goto Addition") << endl;
cout << ("Press S to goto Subtraction") << endl;
cout << ("Type R to goto SquareRoot") << endl;
cout << ("Press C to change color.") << endl;
cout << ("Press W to goto Website Downloader.") << endl;
cout << ("Press Q to exit.") << endl;
cout << ("Press F to goto file writer.") << endl;
cout << ("Mode: ");
}
void ProcessMenu(char MenuOption)
{
switch(d)
{
case 'm':
break; //this is in the wrong place
multiplication();
case 'd':
division();
break;
case 'a':
addition();
break;
case 's':
subtraction();
break;
case 'r':
squareroot();
break;
case 'w':
wget();
break;
case 'q':
return 0;
case 'c':
color();
break;
case 'f':
file();
break;
}
}
void multiplication()
{
system("cls");
cout << ("Multiplication") << endl;
cin >> x;
cin >> y;
cout << ("The answer is:") << x*y << endl;
Sleep(3000);
}
//the other definitions down here as well
|
Your code will fail if the user enters a capital letter, which is what you asked for in the menu. Convert the response to lower case .
You have global variables, which seems easy, but is bad style because it gets messy.
However, I cannot figure out this: |
Did you write it, or is it copied from somewhere?
while (true);
Can you explain what this does? Look up the while statement in the reference pages on this site . Try to figure out how you can rearrange the file() function.
Here's another style issue:
string z, s, t;
do this instead
1 2 3
|
string z; //description of what this for and what is does
string s; //description of what this for and what is does
string WordToOutput; //A word that is output to a file
|
I Don't use single characters for variables - it can lead to confusion. Give things a meaningful name - a word or words joined together.
t could be WordToOutput like I have shown above.
cin >> i;
You haven't said to the user what this for. The program inexplicably seems to stop - the user might not realise they have to input something.
I am confused about what you are doing with this:
1 2 3 4 5 6
|
for (int i; x<i; x++)
{
ofstream a("file.txt", ios::app);
a << t << x << endl;
a.close();
}
|
What is x equal to at the start of the loop?
These shouldn't be in the for loop, they will be executed multiple times.
ofstream a("file.txt", ios::app);
a.close();