Errors in calculator
Apr 19, 2013 at 1:21am UTC
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
float numerator1, denominator1, numerator2, denominator2, answer;
int main (int argc, char *argv[]) {
//Read picture
string line;
ifstream myfile ("/Users/Brad/Desktop/MathScripts/Proportions/Value Finder/picture.txt" );
if (myfile.is_open())
{
while (! myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to load picture!!!" << endl;
//Finish reading picture
//Start Calculator
cout << "Hello! Use 0 as the unknown variable." << endl;
//Start loop
char loop;
do {
cout << "Enter your first ratio:" << endl;
cin >> numerator1;
cin >> denominator1;
cout << "Now your second ratio:" << endl;
cin >> numerator2;
cin >> denominator2;
//Formulas
if (numerator1==0){
answer = denominator1 * numerator2 / denominator2;
}
if (numerator2==0){
answer = numerator1 * denominator2 / denominator1;
}
if (denominator1==0){
answer = numerator1 * denominator2 / numerator2;
}
if (denominator2==0){
answer = denominator1 * numerator2 / numerator1;
}
//Answer
if ((numerator1>0)&&(denominator1>0)&&(numerator2>0)&&(denominator2>0)){
cout << "There is no unknown variable." ;
}else {
//Output answer, if one variable is 0
cout << "Your unknown variable is " << answer << "!" ;
}
}
//End Loop, clear console
cout<< endl <<"Evaluate another ratio? (Y/N)" << endl;
cin>>loop;
cout << string(3, '\n' );
}while (loop=='y' ||loop=='Y' );
if (loop=='n' ){
string endline;
ifstream myfile ("/Users/Brad/Desktop/MathScripts/Proportions/programended.txt" );
if (myfile.is_open())
{
while (! myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to load picture!!!" << endl;
}
}
Errors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Proportions Value Finder.cpp:63:3: error: expected 'while' in do /while loop
cout<< endl <<"Evaluate another ratio? (Y/N)" << endl;
^
Proportions Value Finder.cpp:31:6: note: to match this 'do'
do {
^
Proportions Value Finder.cpp:66:4: error: expected unqualified-id
}while (loop=='y' ||loop=='Y' );
^
Proportions Value Finder.cpp:67:3: error: expected unqualified-id
if (loop=='n' ){
^
Proportions Value Finder.cpp:82:1: error: expected external declaration
}
^
4 errors generated.
I'm confused :(
EDIT: Fixed error 4.
Last edited on Apr 19, 2013 at 1:24am UTC
Apr 19, 2013 at 1:27am UTC
You have an extra } on line 61
Apr 19, 2013 at 1:28am UTC
In response to Yason, I now have one error.
1 2 3 4 5 6 7
Proportions Value Finder.cpp:80:3: error: expected '}'
}
^
Proportions Value Finder.cpp:9:35: note: to match this '{'
int main (int argc, char *argv[]) {
^
1 error generated.
EDIT: Fixed! Thanks
Last edited on Apr 19, 2013 at 1:28am UTC
Topic archived. No new replies allowed.