Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Need help passing strings

$
0
0

Hello all,

I am new to C++ and I am having issues passing string from 2 functions in my code.

When I compile my code, i get the following errors:

Error7error C2065: 'r' : undeclared identifier
Error8error C2065: 'tix' : undeclared identifier

Here is my code:

#include "stdafx.h"
#include <iostream>
#include <iomanip>  
#include <string>

using namespace std;
	
const float base = 50;
float speedLimit;
	float driversSpeed;
	float ticketAmount;
	float speedOver;




string ticketAmountFunc(string r)
{
			/*Calculate the ticket cost as $50 (the base fine rate) plus:
0% additional if the driver's speed was 10 or less miles per hour above the speed limit.
5% additional if driver's speed was more than 10 miles per hour above the speed limit.
10% additional if driver's speed was more than 15 miles per hour above the speed limit
15% additional if driver's speed was more than 20 miles per hour above the speed limit.
20% additional if driver's speed was more than 25 miles per hour above the speed limit.
25% additional if driver's speed was 30 or more miles per hour above the speed limit.
Do not charge a fine if the driver wasn't speeding.*/

	string ticketAmount;

	

		if (speedOver <= 10 && speedOver >= 1)
		{
		ticketAmount = base;
		}

		else if (speedOver <= 14 && speedOver >= 11)
		{
		ticketAmount = (base *.05) + base;
		}

		else if (speedOver <= 19 && speedOver >= 15)
		{
		ticketAmount = (base *.1) + base;
		}

		else if (speedOver <= 24 && speedOver >= 20)
		{
			ticketAmount = (base *.15) + base;
		}

		else if (speedOver <= 29 && speedOver >= 25)
		{
			ticketAmount = (base *.2) + base;
		}

		else if (speedOver >= 30)
		{
		ticketAmount = (base *.25) + base;
		}

		else
		{
			ticketAmount = "0";
		}
	 std::string s = ticketAmount;
	 r = s;
		return r;
}

string finalOutput(string tix)
{
	string words = "Your fine is $";
	 //tix = words + ticketAmountFunc;

	tix = string() + words + ticketAmountFunc(r);

	

	return tix;
}

int _tmain(int argc, _TCHAR* argv[])
{
	cout.precision(2);
	cout.setf(ios::fixed,ios::floatfield);


	string repeat;
	
	/*Use a symbolic constant for the base ticket fine rate ($50).*/


	start:
	/*Prompt the user for the speed limit and the speed of the driver.*/
	cout << "Enter the speed limit: ";

	cin >> speedLimit;

	cout << "Enter the driver's speed: ";

	cin >> driversSpeed;

	/*Display to the user the values which were input (speed limit and driver's speed) and the calculated ticket fine amount. Print 2 numbers after the decimal point for the fine amount. Make sure your output format matches the sample format.*/

	cout << "You were driving " << driversSpeed << " in a " << speedLimit << " mph zone.\n";
	    speedOver = driversSpeed - speedLimit; 


		cout << string(finalOutput(tix));

		/*After the fine is printed for the first speeding violation, prompt the user to see if he/she wants to enter another speeding violation. If so, prompt again for the speed limit and driver's speed. Repeat the calculation and print the fine. Repeat this process until the user indicates he/she wants to stop.  The user can enter either an uppercase or lowercase letter Y to continue with the program.*/

		cout << "\nEnter Y to continue.  Anything else to stop: ";

		cin >> string(repeat);

		if (repeat == "Y" || "y")
			goto start;
		else 
			exit(0);

}

Please help. Thank you.


Viewing all articles
Browse latest Browse all 15302


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>