Beginner looking for help

Brand new to all of this, and I'm trying to make two programs,

One that stores the integers 62 and 99 in variables, and stores the sum of these two in a variable named total.

Second one that will predict how much a company will generate if the company has x money in sales in 1 year, based off a %. I'll leave both of them below seperated.

For the first one, it says line 19 'c' was not declared in this scope, and line 16, expected initializer before 'Three'

For the second program, the error is saying expected initializer before 'integers'


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

 #include <iostream>
 using namespace std;

int main()

{

	int a, b, c Three integers;
 	a = 62;
 	b = 99;
 	c = 62 + 99;
 	cout < "The value of 62 + 99 is 161" < c;
 	
 system("pause");
 return 0;

}



 #include <iostream>
 using namespace std;

int main()
{
	int a, b, c, Three integers;
	a=0.62;
	b=4600000;
	c=0.62 + 4600000;
	cout < "The value of 0.62+4600000 is 2852000";
 
 system("pause");
 return 0;   

}



Problem in both programs :
cout <

It's << not < - cout <<

http://www.cplusplus.com/doc/tutorial/basic_io/

First program:

int a, b, c Three integers;

What is this "Three integers" thing? Is it a varaible? You cant have spaces in variable names. Is it supposed to be a comment? Then add a // before.
 
int a, b, c; // Three Integers 


Second Program:

Same as above + this - a=0.62;

0.62 is for obvious reasons not an integer. If you want decimals declare it double or float.
 
float a;




Also, what is the point of having the variables if you're not gonna use them?

cout < "The value of 62 + 99 is 161" < c;
should be:
cout << "The value of " << a << " + " << b << " is " << c;
Last edited on
Hey, to start things off, it's nice that you show an attempt at doing it.

Second, a program can't have 2 int main(). This is because int main() is the starting point, and what will execute all your code.

So, the first assignment is to assign 3 variables. Two numbers, and then a total.

1
2
3
4
5
6
7
8
9
10
11
int main(){
	int a, b, total;
	a = 62;
	b = 99;
	total = a + b;
	std::cout << "The value of 62 + 99 = " << total << std::endl;

        char ch;
        std::cin >> ch;     // I rather use char ch, and then std::cin instead of system(commands)
	return 0;
}


^ Something like that can be done for part 1 of your question.

I'm going to do #2 now, so I'll report back when done, unless someone does it before me.

EDIT: Before I go, please check how you declared your integers. You can't have int a, b, c, three integers. You can have int a, b, c, threeIntegers or ThreeIntegers, but you can't seperate them, it has to be ONE word.

Another thing, are lines 28 and 30 not giving you errors? You're declaring a as an int in your program, and then assigning it a float value

Edit2: Tarik beat me to it, and he's about to give you one badass explanation it seems.
Last edited on
I have all of it fixed except for the Second program, line 27 + 28 , i would've assumed it went something like int float a, b, c; // Three integers followed by float a = 0.62;

EDIT: Got it, had to put //float a for lines 28 + 31
Last edited on
Yes, that's kind of what I was telling you.

I said that lines 28 and 30 are supposed to give errors, because you declared a, b, c as an int, and then you are using floating point values for a in the next line.

I'm glad you got it fixed though :)
Topic archived. No new replies allowed.