Please Help me understand my errors

Getting some logical errors

Page 1 of 1

1 Replies - 483 Views - Last Post: 19 October 2008 - 08:01 PM Rate Topic: -----

#1 jingoria  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 96
  • Joined: 22-October 07

Please Help me understand my errors

Post icon  Posted 19 October 2008 - 07:36 PM

HI,
I was writing a program that would pass a string to an array, reverse the string and then pass it to another array.
Half way through I compiled my program and getting some weird output.
My code so far is:
// Hw-4_Bhasin.cpp : Defines the entry point for the console application.

void rev_str(void);
double Mean(const int Data[5][4], int, int);
void frequency(const int Data[5][4], int, int);
#include "stdafx.h"
#include<iostream>
#include<string>
#include<cmath>
using namespace std;



int main()
{
	
	char option;

	cout<<"\n	Please choose from the given menu.";
	cout<<"\n	R{Reverse String]	M[Matrix]	Q[Quit]."<<endl;
	cin>> option;

	switch(option)
	{
	case 'R':
		 rev_str();
		 break;
	case 'r':
		rev_str();
		break;

	}
	system("pause");
	return 0;
}

void rev_str(void)
{
	const int MAX = 100;
	char Input_String[MAX];
 
	cout<<"Please enter a string."<<endl;
	cin.get(Input_String, MAX);

	cout<<Input_String;

	for(int i=0; i<MAX; i--)
		cout<<Input_String<<endl;

	system("pause");
	return;
}



When declaring all my functions as global, I get 2 errors state that 'rev_str': identifier not declared. In other words it does not recognize my call to the function in the switch statement.

So I simply, placed a function prototype inside the main(). After this when I execute my program, it asks me for my option. When I press r or R, the screen blanks out. Seems like the compiler does not even reads the function definition.

What can I do?
Please help me.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Please Help me understand my errors

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: Please Help me understand my errors

Posted 19 October 2008 - 08:01 PM

Put a cin.ignore() after your cin >> option to get rid of the newline that's stuck in the buffer.

Also, this loop is wrong...it's infinite. Think about it.
for(int i=0; i<MAX; i--)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1