Hi, I am new to programming and I cant figure out what I am doing wrong.
I sure bought the wrong book to self teach myself. haha
This is the problem i need to solve.
i. Prompt the user for a numerator value.
ii. Store the user-entered value in a variable numerator.
iii. Prompt the user for a denominator value.
iv. Store the user-entered value in a variable denominator.
v. Call the fractionToDecimal() function, passing numerator and denominator as arguments.
vi. Display the value returned by the fractionToDecimal() function along with a message like "The fraction 3/4 is equal to the the decimal value 0.75".
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
|
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double numerator;
double denominator;
char choice;
bool quit = false;
do {
cout<<("A. Add two fractions \nB. Convert a fraction to decimal \nC. Multiply two fractions \nQ. Quit");
cin>>choice;
switch(choice){
case 'A':
cout<<("adding two fractions")<<endl;
break;
case 'B':
cout<<("Please enter a numerator")<<endl;
cin>> numerator;
cout<<("Please enter a denominator")<<endl;
cin>> denominator;
double q2 = fractionToDecimal(numerator,denominator);
cout<<q2;
break;
case 'C':
cout<<("Multiply two fractions")<<endl;
break;
case 'Q':
cout<<("Quit")<<endl;
quit = true;
break;
}
}while (quit != false);
system("pause");
return 0;
}
double fractionToDecimal(int numerator, int denominator){
double quotient;
if (denominator == 0){
cout<<("This is invalid");
quotient = 0;
}
else {
quotient = numerator / denominator;
}
return quotient;
}
|
error messages i'm getting:
fractionToDecimal': identifier not found
(51)initialization of 'q2' is skipped by 'case' label
(42) : see declaration of 'q2'