help

Hey, I just began coding today and I need help with this code ( when I try to execute it says it has 2 errors).Thanks!

1
2
3
4
5
6
7
8
9
10
#include <iostream>
int a,b,c,r;
int main () {
	std::cout <<"a="; std::cin>>a;
	std::cout <<"b="; std::cin>>b;
	c=a/b;r=a%b;
	std::cout<<"quotient="<<c<<'\n';
	std::cout<<"rest="<<r;
	return 0;
}
Last edited on
It looks just fine to me, aside for some formatting. It ran with no errors.
It worked fine for me too. What sort of error is it?

Today is also my first day of coding (in any language). I wanted to re-create what you did with what I have learned. Being a newbie, I don't really know how sloppy my code is.

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
#include <iostream>
using namespace std;

int main()
{
	int dividend;
	int divisor;
	int remainder;
	int quotient;

	cout << "Please choose a dividend: ";
	cin >> dividend;
	cout << endl << "Now, please choose a divisor: ";
	cin >> divisor;
	
	quotient = dividend / divisor;
	cout << endl << dividend << " divided by " << divisor << " is " << quotient ;
	
	remainder = dividend % divisor;
	if (remainder > 0)
	{
		cout << " with a remainder of " << remainder << "." << endl;
	}
	else
	{
		cout << "." << endl;
	}


	return 0;
}
closed account (48T7M4Gy)
Don't be afraid of using white space and clear output text.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

int main ()
{
    int a = 0;
    int b = 0;
    int c = 0;
    int r = 0;
    
   std::cout << "a = ";
   std::cin >> a;
	
   std::cout << "b = ";	
   std::cin >> b;
   std::cout << std::endl;
	
   c = a / b;
   std::cout << "Quotient = " << c << '\n';
	
   r = a % b;
   std::cout << "Remainder = " << r;
	
   return 0;
}
Last edited on
Topic archived. No new replies allowed.