Please help with code

I received some help with my code earlier. I just have one more problem the error I get is line: 77 col: 10 Sel: 0 Lines: 80 Length: 1078 insert Done parsing in 0.36 seconds Here is
1
2
3
4
5
6
my code.

//Eric Gilliam
// CS104
// 4-13-2016
#include <iostream> 

using namespace std;








int myArray [] = {11, 9, 63, 27, 85};// my Array
int n, result=0;

int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main(){
int t;
switch (t) {
case 1:
case 2:
case 3:
cout << "t is 1, 2 or 3";
break;
default:
cout << "t is not 1, 2 nor 3";
break;


}




{

for ( n=0 ; n<5 ; ++n )
{
result += myArray[n];
}
int z;
z = addition (5,3);
cout << "The result is " << z;

double den, num, result;
char op;
do{
cout << "\nCalculator - Please enter a number :";
cin >> num;
cout << "Please enter a what kind of math +, -, *, /";
cin >> op;

cout << "Please enter second number :";

cin >> den;
if (op=='+') result=num+den;
// How the calculator calculates
if (op=='-') result=num-den;
if (op=='*') result=num*den;
if (op=='/') result=num/den;
cout<< result;
}
while (op!='e');
cout<<"HELLO WORLD MY NAME IS ERIC! "<< endl;






return 0;
}

Last edited on
Line 25: t is an uninitiailized (garbage) variable.

Line 26: You use an uninitialized variable in your switch statement.

Line 36: You have an extraneous {

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thanks for the help I fixed line 36 but I cant get my variable to initiailize.


//Eric Gilliam
// CS104
// 4-13-2016
#include <iostream>
using namespace std;








int myArray [] = {11, 9, 63, 27, 85};// my Array
int n, result=0;

int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main(){
int t;
switch (t) {
case 1:
case 2:
case 3:
cout << "t is 1, 2 or 3";
break;
default:
cout << "t is not 1, 2 nor 3";
break;







{

for ( n=0 ; n<5 ; ++n )
{
result += myArray[n];
}
int z;
z = addition (5,3);
cout << "The result is " << z;

double den, num, result;
char op;
do{
cout << "\nCalculator - Please enter a number :";
cin >> num;
cout << "Please enter a what kind of math +, -, *, /";
cin >> op;

cout << "Please enter second number :";

cin >> den;
if (op=='+') result=num+den;
// How the calculator calculates
if (op=='-') result=num-den;
if (op=='*') result=num*den;
if (op=='/') result=num/den;
cout<< result;
}
while (op!='e');
cout<<"HELLO WORLD MY NAME IS ERIC! "<< endl;






return 0;
}

You've initialised the variables n and result variables (albeit globally), so how come you're unable to initialise t?
What does myArray[n] mean? Sorry, but I'm new in programming.
George1987 wrote:
What does myArray[n] mean?

It retrieves the element of myArray at index n.
You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
Topic archived. No new replies allowed.