Debugging code
Oct 28, 2015 at 10:19pm UTC
Okay so I am given code which needs to be fixed. All logic and syntax error need to be fixed. I don't understand where there are logical errors. Can someone look at the code and explain it to me and possibly where the logical errors are?
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
/*
Name: debug1.cpp
Author: VG
Date: 09/10/15 11:35
Description: A simple debugging exercise
*/
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
int num1 = 0, num2 = 0;
bool found = false ;
string str1 = "" ;
cout << "Enter two integers: " ;
cin >> num1 >> num2;
cout << endl;
if ((num1 >= num2) && num2 > 0)
{
switch (num1 % num2)
{
case 1:
found = (num1/num2) <= 6;
break ;
case 2:
num1 = num2 / 2;
break ;
default :
num2 = num1 * num1;
} //end switch
}//end if
if (found)
str1 = "True" ;
else
str1 = "False" ;
cout << num1 << " " << num2 << " " << str1 << endl;
system("Pause" );
return 0;
}//end main
Topic archived. No new replies allowed.