expected initializer before "std"

#include <iostream>

int main()

{



int n,a,b,c,s

std::cout<<"n="; std::cin>>n;

a=n/100;

b=n/10%10;

c=n%10;

s=a+b+c;

std::cout<<"The digits sum is:"<<s;

return 0;

}

What did I do wrong here? It tells me that the "std::cout<<"n="; std::cin>>n;" line is wrong and says "expected initializer before "std"".Write your question here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main()
{
    int n,a,b,c,s; //was missing a semicolon here

    std::cout << "n = ";
    std::cin >> n;

    a = n / 100;
    b = n / 10 % 10;
    c = n % 10;
    s = a + b + c;

    std::cout << "\nThe digits sum is: " << s;

    return 0;
}
Last edited on
closed account (E0p9LyTq)
int n,a,b,c,s has no semi-colon.

PLEASE learn to use code tags, it makes it easier to read your code.

You can edit your post and add the tags.

http://www.cplusplus.com/articles/jEywvCM9/

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
#include <iostream>

int main()

{



   int n, a, b, c, s

   std::cout << "n="; std::cin >> n;

   a = n / 100;

   b = n / 10 % 10;

   c = n % 10;

   s = a + b + c;

   std::cout << "The digits sum is:" << s;

   return 0;

}
Topic archived. No new replies allowed.