block characters and loop program

hello guys, i am having some problems with my code (i am an absolute beginner by the way). i am creating a program where the user gives me the input of his "buying price" and "sale Price" and i tell him how much profit he made. i am trying to make it in a way so that whenever a user puts in an alphabet it just tells him invalid input and also one more problem i encountered was that when i ask the user if they would like to calculate again, when the input is yes it asks for the amount of products and then goes straight to amount of investment instead of going through the whole process again. please help me out if you can. thank you
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 #include "stdafx.h"
#include <iostream>
#include <limits>
using namespace std;


int main()

{
	float money = 0, convert = 0;
	float investment = 0;
	float salePrice = 0;
	float price = 0;
	float total = 0;
	float goods = 0;
	float amountLeft = 0;
	float profit = 0, nprofit = 0;
	int c = 1;
	char option = 'y';



	do{


	do{
		cout << "Enter the amount of product you bought" << endl;
		cin >> goods;
		
		
		

	} while (goods <= 0);
	while (c <= goods){

		do{
			cout << " Enter the price for product " << c << endl;
			cin >> price;

			
		} while (price <= 0);

		do{
			cout << " Enter the amount you sold for product" << c << endl;
			cin >> salePrice;

			
		} while (salePrice <= 0);
		if (price < salePrice){
			nprofit = salePrice - price;
			cout << " you made  RM" << nprofit << " profit on this product" << endl;
		}
		else if (price > salePrice){
			nprofit = price - salePrice;
			cout << "you made no profit on this product" << "( you lost RM" << nprofit << ")" << endl;
		}
		else{
			cout << "you made no profit  neither was their any loss for this product" << endl;
		}
		total = total + price;

		c++;
	}

	do{
		cout << "Enter the amount of money you have for investment" << endl;
		cin >> investment;

		
	} while (investment <= 0);
	amountLeft = investment - total;
	if (amountLeft <= 0){

		cout << "you have no money left for further investment" << endl;
	}
	else if (amountLeft > 0){
		cout << "you still have RM" << amountLeft << " amount left for investment" << endl;
	}
	else{

	}

	cout << "would you still like to invest in a different product (y/n)" << endl;
	cin >> option;

}while (option == 'y' );
	
	cout << "" << endl;
	 cout << "to help you trade successfuly, this is a simple currency converter from RM to US dollars" << endl;

	do{
		cout << "how much do you want to convert?" << endl;
		cin >> money;

		
	} while (money <= 0);
	convert = money * 0.31;
	
	cout << "this is how much RM" << money << " is in USD : " << convert << endl;


	cout << "Thank you for using this Program, goodluck with your business." << endl;


	return 0;
}


/*
if (cin.fail()) {
				cin.clear();
				cin.ignore();
				cout << endl << "That wasn't a number " << endl;
				

			}

*    ( this is the code i tried)\
 */









Topic archived. No new replies allowed.