Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

C program gives a random incorrect output

+1 vote
asked Feb 19, 2018 by Kiratjit Singh (130 points)
When I run my program it gives a random answer.
This is my code:
/*
File: Transformation.c
Purpose: .......*/

#include <stdio.h>

int
main ()
{
  //Declare variables
  int x;
  int y;
  int coordinatepoint;
  int reflectxoverx;
  int reflectxovery;
  int x_opasite;
  int y_opasite;
  int x2;
  int y2;
  int RotChoice;
  int Ninety_CCW_x ;
  int Ninety_CCW_y ;
  int Ninety_CW_x ;
  int Ninety_CW_y ;
  int One_Eighty_x;
  int One_Eighty_y;      
  int units_moved_right;             
  int units_moved_left;
  int units_moved_up;
  int units_moved_down;
  int new_translated_point_x;
  int new_translated_point_y;
   
    //Assign value to variables
 
  printf ("Please enter an x value:\n");
  scanf ("%d", &x);
  printf ("Please enter a y value:\n");
  scanf ("%d", &y);
 
  x_opasite = -x;
  y_opasite = -y;
 
  Ninety_CW_x = -y;
  Ninety_CW_y = x ;
 
  Ninety_CCW_x = y ;
  Ninety_CCW_y = -x;
 
  One_Eighty_x = -x;
  One_Eighty_y = -y;
 
  new_translated_point_x = x - units_moved_left + units_moved_right;
  new_translated_point_y = y - units_moved_down + units_moved_up;
 
 
  printf ("Your coordinate point is (%d,%d)\n", x, y);
  printf ("Your coordinate point reflected across the x axis is (%d,%d)\n", x,y_opasite);
  printf ("Your coordinate point reflected across the y axis is (%d,%d)\n",x_opasite, y);
 
  LOOP:  
 
  printf ("Please choose a rotation choice:\n");
  printf ("1: Rotate 90 degrees clockwise\n");
  printf ("2: Rotate 90 degrees counterclockwise\n");
  printf ("3: Rotate 180 degrees\n");
  scanf ("%d", &RotChoice);
 
 
 
   if (RotChoice == 1) {
    
      printf ("Your new coordinate point that has been rotated 90 degrees clockwise is:\n");
      printf ("(%d,%d)\n", Ninety_CW_x, Ninety_CW_y);
    
 }
     
  if (RotChoice == 2) {
 
  printf ("Your new coordinate point that has been rotated 90 degrees counterclockwise is:\n");
  printf ("(%d,%d)\n", Ninety_CCW_x, Ninety_CCW_y);
 
  }
 
  if (RotChoice == 3) {
  printf ("Your new coordinate point that has been roatated 180 degress is:\n");
  printf ("(%d,%d)\n", One_Eighty_x, One_Eighty_y);
     
  }

 do {
     
     
      if( RotChoice > 3)
  { printf ("Invlaid input\n");
  printf ("Please try again-\n");

  
       goto LOOP;
      break;
  }
 
  
  if (RotChoice == 3 || 2 || 1)
 
  break;
 
   }
  
   while (RotChoice != 3 || 2 || 1 );
  

THIS IS THE PART OF THE PROGRAM THAT I NEED HELP WITH, THE REST WORKS. THIS IS FOR TRANSLATION OF A COORDINATE POINT.

  
  printf ("Please enter some instructions for a new traslated coordinate point:\n");
  printf ("How many units would you like to move your point right:\n");
  scanf ("%d", &units_moved_right);
  printf ("How many units would you like to move your point left:\n");
  scanf ("%d", &units_moved_left);
  printf ("How many units would you like to move your point up:\n");
  scanf ("%d", &units_moved_up);
  printf ("How many units would you like to move your point down:\n");
  scanf ("%d", &units_moved_down);
 
  printf ("Your new translated coordinate point is (%d,%d)", new_translated_point_x, new_translated_point_y);
   
           return 0;}

 
It gives a random output for the y value:
Your new translated point is (1, 4196590).
Sorry the spacing is messed up.

1 Answer

0 votes
answered Feb 20, 2018 by anonymous
Ouch, that a logic error.

I got that when I made a quadratic formula calculator.

They'll happen and I really don't know how to fix them.
commented Sep 22, 2020 by Kiratjit Singh (130 points)
okay thx but i graduated high school and im in MIT now. im a mathematic major but i am still stuck on this. Despite qualifying for USAMO im still confucian. Maybe the use of chebyshevs inequlity will help .

thx
nigeriian prince
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...